Submission #1117054
Source Code Expand
#include <cstdio> #include <cstring> const int nmax=100023; char ch[nmax]; int n; int sol[nmax]; int left(int pos) { if(pos==0) return n-1; return pos-1; } int right(int pos) { if(pos==n-1) return 0; return pos+1; } int check(int pos) { int ct=0; while(1) { if(sol[left(pos)]!=0&&sol[right(pos)]!=0) ++ct; if(ct==n+2) break; if(sol[pos]==1) { if(ch[pos]=='o') { if(sol[left(pos)]!=sol[right(pos)]&&sol[right(pos)]!=0&&sol[left(pos)]!=0) return 0; sol[right(pos)]=sol[left(pos)]; } else if(ch[pos]=='x') { if(sol[left(pos)]==sol[right(pos)]) return 0; sol[right(pos)]=3-sol[left(pos)]; } } else { if(ch[pos]=='x') { if(sol[left(pos)]!=sol[right(pos)]&&sol[right(pos)]!=0&&sol[left(pos)]!=0) return 0; sol[right(pos)]=sol[left(pos)]; } else { if(sol[left(pos)]==sol[right(pos)]) return 0; sol[right(pos)]=3-sol[left(pos)]; } } pos=right(pos); } return 1; } void reset() { for(int i=0;i<n;i++) sol[i]=0; } int main() { // freopen ("in.in","r",stdin); scanf("%d",&n); scanf("%s",ch); int pos=-1; for(int i=0;i<n;i++) { if(ch[i]=='o') { pos=i; break; } } if(pos==-1) { printf("-1\n"); return 0; } sol[pos]=1,sol[left(pos)]=1,sol[right(pos)]=1; if(check(right(pos))) { for(int i=0;i<n;i++) { if(sol[i]==1) printf("S"); else printf("W"); } return 0; } reset(); sol[pos]=1,sol[left(pos)]=2,sol[right(pos)]=2; if(check(right(pos))) { for(int i=0;i<n;i++) { if(sol[i]==1) printf("S"); else printf("W"); } return 0; } reset(); sol[pos]=2; sol[left(pos)]=1,sol[right(pos)]=2; if(check(right(pos))) { for(int i=0;i<n;i++) { if(sol[i]==1) printf("S"); else printf("W"); } return 0; } reset(); sol[pos]=2; sol[left(pos)]=2,sol[right(pos)]=1; if(check(right(pos))) { for(int i=0;i<n;i++) { if(sol[i]==1) printf("S"); else printf("W"); } return 0; } printf("-1\n"); }
Submission Info
Submission Time | |
---|---|
Task | D - Menagerie |
User | ArifOzturk |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 2673 Byte |
Status | AC |
Exec Time | 7 ms |
Memory | 768 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:61:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&n); ^ ./Main.cpp:62:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s",ch); ^
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 | 0 ms | 128 KB |
00_example_02.txt | AC | 0 ms | 128 KB |
00_example_03.txt | AC | 0 ms | 128 KB |
01.txt | AC | 5 ms | 512 KB |
02.txt | AC | 2 ms | 384 KB |
03.txt | AC | 1 ms | 128 KB |
04.txt | AC | 0 ms | 128 KB |
05.txt | AC | 6 ms | 640 KB |
06.txt | AC | 4 ms | 640 KB |
07.txt | AC | 1 ms | 256 KB |
08.txt | AC | 1 ms | 256 KB |
09.txt | AC | 1 ms | 128 KB |
10.txt | AC | 1 ms | 256 KB |
11.txt | AC | 6 ms | 768 KB |
12.txt | AC | 6 ms | 768 KB |
13.txt | AC | 7 ms | 768 KB |