Submission #548630

#TimeUsernameProblemLanguageResultExecution timeMemory
548630AmylopectinThree Friends (BOI14_friends)C++14
100 / 100
63 ms4704 KiB
#include <iostream> #include <stdio.h> using namespace std; const int mxn = 2e6 + 10; char s[mxn] = {}; int let[31] = {}; int main() { int i,j,n,m,odd,cou = 0,cl,cr,ans[2] = {},of; scanf("%d %s",&n,&s); for(i=0; i<n; i++) { let[s[i] - 'A'] ++; } for(i=0; i<26; i++) { if(let[i] % 2 == 1) { cou ++; odd = i; } } if(cou != 1 || n % 2 == 0) { printf("NOT POSSIBLE\n"); return 0; } cl = 0; cr = n/2; for(j=0; j<2; j++) { if(j == 1) { cl = 0; cr = n/2 + 1; } of = 0; for(i=0; i<n/2; i++) { if(s[cl] != s[cr]) { of ++; if(of > 1) { break; } if(j == 0) { // if(s[cr] - 'A' != odd) // { // of = 2; // break; // } cr ++; } else { // if(s[cl] - 'A' != odd) // { // of = 2; // break; // } cl ++; } i--; } else { cl ++; cr ++; } } if(of >= 2) { ans[j] = -1; } else ans[j] = 1; } if(ans[0] == 1) { if(ans[1] == 1) { of = 0; for(i=0; i<n/2; i++) { if(s[i] != s[i+n/2+1]) { of = 1; break; } } if(of == 1) printf("NOT UNIQUE\n"); else { for(i=0; i<n/2; i++) { printf("%c",s[i]); } printf("\n"); } } else { for(i=0; i<n/2; i++) { printf("%c",s[i]); } printf("\n"); } } else { if(ans[1] == 1) { for(i=n/2+1; i<n; i++) { printf("%c",s[i]); } printf("\n"); } else { printf("NOT POSSIBLE\n"); } } return 0; }

Compilation message (stderr)

friends.cpp: In function 'int main()':
friends.cpp:11:16: warning: format '%s' expects argument of type 'char*', but argument 3 has type 'char (*)[2000010]' [-Wformat=]
   11 |     scanf("%d %s",&n,&s);
      |               ~^     ~~
      |                |     |
      |                char* char (*)[2000010]
friends.cpp:10:15: warning: unused variable 'm' [-Wunused-variable]
   10 |     int i,j,n,m,odd,cou = 0,cl,cr,ans[2] = {},of;
      |               ^
friends.cpp:10:17: warning: variable 'odd' set but not used [-Wunused-but-set-variable]
   10 |     int i,j,n,m,odd,cou = 0,cl,cr,ans[2] = {},of;
      |                 ^~~
friends.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%d %s",&n,&s);
      |     ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...