Submission #2831222
Source Code Expand
#include<iostream> #include<string> #include<cmath> #include<cstdlib> #include<vector> #include<map> #include<set> #include<algorithm> #include<queue> using namespace std; string s; int n; string ans; char notchar(char now){ if(now == 'S') return 'W'; else return 'S'; } char next(char prepre,char pre,char now){ if(pre == 'S'){ if(now == 'o') return prepre; else return notchar(prepre); } else { if(now == 'o') return notchar(prepre); else return prepre; } } bool check(string ans){ bool prev; if(ans[n-1] == 'S'){ if(s[n-1] == 'o'){ prev = (ans[0] == ans[n-2]); } else { prev = (ans[0] != ans[n-2]); } } else { if(s[n-1] == 'o'){ prev = (ans[0] != ans[n-2]); } else { prev = (ans[0] == ans[n-2]); } } bool now; if(ans[0] == 'S'){ if(s[0] == 'o'){ now = (ans[1] == ans[n-1]); } else { now = (ans[1] != ans[n-1]); } } else { if(s[0] == 'o'){ now = (ans[1] != ans[n-1]); } else { now = (ans[1] == ans[n-1]); } } return now & prev; } int main(){ cin>>n>>s; ans = "SS"; for(int i=1;i<n-1;i++){ ans += next(ans[i-1],ans[i],s[i]); } if(check(ans)){ cout<<ans<<endl; return 0; } ans = "SW"; for(int i=1;i<n-1;i++){ ans += next(ans[i-1],ans[i],s[i]); } if(check(ans)){ cout<<ans<<endl; return 0; } ans = "WS"; for(int i=1;i<n-1;i++){ ans += next(ans[i-1],ans[i],s[i]); } if(check(ans)){ cout<<ans<<endl; return 0; } ans = "WW"; for(int i=1;i<n-1;i++){ ans += next(ans[i-1],ans[i],s[i]); } if(check(ans)){ cout<<ans<<endl; return 0; } cout<<"-1"<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Menagerie |
User | kaming |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 1813 Byte |
Status | AC |
Exec Time | 9 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 | 6 ms | 512 KB |
02.txt | AC | 3 ms | 512 KB |
03.txt | AC | 1 ms | 256 KB |
04.txt | AC | 1 ms | 256 KB |
05.txt | AC | 7 ms | 640 KB |
06.txt | AC | 5 ms | 640 KB |
07.txt | AC | 2 ms | 256 KB |
08.txt | AC | 2 ms | 384 KB |
09.txt | AC | 1 ms | 256 KB |
10.txt | AC | 3 ms | 384 KB |
11.txt | AC | 9 ms | 640 KB |
12.txt | AC | 9 ms | 640 KB |
13.txt | AC | 8 ms | 640 KB |