Submission #2831418
Source Code Expand
#include <iostream> #include <cstdio> #include <algorithm> #include <string> using namespace std; int n; char s[100002]; int f (int i, char a, char b, char* ans) { if (i == n) { if (b == 'S') { if (s[n-1] == 'o' && ans[0] != a) return 1; else if (s[n-1] == 'x' && ans[0] != (a == 'S'?'W':'S')) return 1; } else { if (s[n-1] == 'x' && ans[0] != a) return 1; else if (s[n-1] == 'o' && ans[0] != (a == 'S'?'W':'S')) return 1; } if (ans[0] == 'S') { if ( s[0] == 'o' && ans[1] != b) {return 1;} else if (s[0] == 'x' && ans[1] != (b == 'S'?'W':'S')) {return 1;} } else { if (s[0] == 'x' && ans[1] != b) return 1; else if (s[0] == 'o' && ans[1] != (b == 'S'?'W':'S')) return 1; } return 0; } if (b == 'S') { if (s[i-1] == 'o') ans[i] = a; else ans[i] = a == 'S'? 'W' : 'S'; } else { if (s[i-1] == 'x') ans[i] = a; else ans[i] = a == 'S'? 'W' : 'S'; } return f(i+1, b, ans[i], ans); } int main () { int ret; string str = ""; char ans[1000002]; cin >> n >> s; for (int i = 0; i < n + 1; i++) ans[i]=0; if ( f(2, ans[0] = 'S', ans[1] = 'S', ans) && f(2, ans[0] = 'W', ans[1] = 'S', ans) && f(2, ans[0] = 'S', ans[1] = 'W', ans) && f(2, ans[0] = 'W', ans[1] = 'W', ans) ) { cout << -1 << endl; } else cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Menagerie |
User | hibitomo |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 1425 Byte |
Status | AC |
Exec Time | 6 ms |
Memory | 512 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 | 4 ms | 384 KB |
02.txt | AC | 3 ms | 384 KB |
03.txt | AC | 1 ms | 256 KB |
04.txt | AC | 1 ms | 256 KB |
05.txt | AC | 5 ms | 512 KB |
06.txt | AC | 4 ms | 512 KB |
07.txt | AC | 2 ms | 256 KB |
08.txt | AC | 2 ms | 256 KB |
09.txt | AC | 1 ms | 256 KB |
10.txt | AC | 2 ms | 256 KB |
11.txt | AC | 6 ms | 512 KB |
12.txt | AC | 6 ms | 512 KB |
13.txt | AC | 5 ms | 512 KB |