Submission #1115955
Source Code Expand
#include <bits/stdc++.h> using namespace std; using VI = vector<int>; using VVI = vector<VI>; using PII = pair<int, int>; using LL = long long; using VL = vector<LL>; using VVL = vector<VL>; using PLL = pair<LL, LL>; using VS = vector<string>; #define ALL(a) begin((a)),end((a)) #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define EB emplace_back #define MP make_pair #define SZ(a) int((a).size()) #define SORT(c) sort(ALL((c))) #define RSORT(c) sort(RALL((c))) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define FF first #define SS second template<class S, class T> istream& operator>>(istream& is, pair<S,T>& p){ return is >> p.FF >> p.SS; } template<class S, class T> ostream& operator<<(ostream& os, const pair<S,T>& p){ return os << p.FF << " " << p.SS; } template<class T> void maxi(T& x, T y){ if(x < y) x = y; } template<class T> void mini(T& x, T y){ if(x > y) x = y; } const double EPS = 1e-10; const double PI = acos(-1.0); const LL MOD = 1e9+7; int main(){ cin.tie(0); ios_base::sync_with_stdio(false); int N; cin >> N; string S; cin >> S; string ws = "WS"; string ans(N, '0'); REP(x0,2) REP(x1,2){ ans[0] = ws[x0]; ans[1] = ws[x1]; for(int i=1;i+1<N;++i){ if(ans[i] == 'S'){ if(S[i] == 'o'){ ans[i+1] = ans[i-1]; } else{ ans[i+1] = (ans[i-1]=='S'?'W':'S'); } } else{ if(S[i] == 'x'){ ans[i+1] = ans[i-1]; } else{ ans[i+1] = (ans[i-1]=='S'?'W':'S'); } } } bool ok = true; if(ans.back() == 'S'){ if(S.back() == 'o') ok = ok && ans[N-2] == ans[0]; else ok = ok && ans[N-2] != ans[0]; } else{ if(S.back() == 'x') ok = ok && ans[N-2] == ans[0]; else ok = ok && ans[N-2] != ans[0]; } if(ans[0] == 'S'){ if(S[0] == 'o') ok = ok && ans[N-1] == ans[1]; else ok = ok && ans[N-1] != ans[1]; } else{ if(S[0] == 'x') ok = ok && ans[N-1] == ans[1]; else ok = ok && ans[N-1] != ans[1]; } if(ok){ cout << ans << endl; return 0; } } cout << -1 << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Menagerie |
User | okaduki |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 2173 Byte |
Status | AC |
Exec Time | 5 ms |
Memory | 640 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt |
All | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_example_01.txt | AC | 1 ms | 256 KB |
00_example_02.txt | AC | 1 ms | 256 KB |
00_example_03.txt | AC | 1 ms | 256 KB |
01.txt | AC | 2 ms | 512 KB |
02.txt | AC | 2 ms | 384 KB |
03.txt | AC | 1 ms | 256 KB |
04.txt | AC | 1 ms | 256 KB |
05.txt | AC | 3 ms | 640 KB |
06.txt | AC | 5 ms | 640 KB |
07.txt | AC | 2 ms | 384 KB |
08.txt | AC | 2 ms | 384 KB |
09.txt | AC | 1 ms | 256 KB |
10.txt | AC | 2 ms | 256 KB |
11.txt | AC | 2 ms | 592 KB |
12.txt | AC | 2 ms | 592 KB |
13.txt | AC | 3 ms | 592 KB |