Submission #54989

#TimeUsernameProblemLanguageResultExecution timeMemory
54989cki86201Three Friends (BOI14_friends)C++11
100 / 100
34 ms26684 KiB
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <memory.h> #include <math.h> #include <assert.h> #include <queue> #include <map> #include <set> #include <string> #include <algorithm> #include <iostream> #include <functional> #include <unordered_map> #include <unordered_set> #include <list> #include <bitset> #include <complex.h> using namespace std; typedef pair<int, int> pii; typedef long long ll; #define Fi first #define Se second #define pb(x) push_back(x) #define szz(x) ((int)(x).size()) #define rep(i, n) for(int i=0;i<n;i++) #define all(x) (x).begin(), (x).end() typedef tuple<int, int, int> t3; typedef pair<ll, ll> pll; typedef long double ldouble; typedef pair<double, double> pdd; int N; char S[2000020]; char T1[2000020]; char T2[2000020]; void solve(){ scanf("%d", &N); scanf("%s", S+1); if(N % 2 == 0) { puts("NOT POSSIBLE"); return; } for(int i=1;i<=N-1;i++) { if(i <= N / 2) T1[i] = S[i]; else T1[i] = S[i - N/2]; } int ok = 3; int f1 = -1; for(int i=1;i<=N-1;i++) if(S[i] != T1[i]) { f1 = i; break; } if(f1 != -1) { for(int i=f1+1;i<=N;i++) if(S[i] != T1[i-1]) { ok ^= 1; break; } } for(int i=N;i>N-N/2;i--) T2[i-1] = S[i]; for(int i=N/2;i;i--) T2[i] = T2[i+N/2]; f1 = -1; for(int i=1;i<=N-1;i++) if(S[i] != T2[i]) { f1 = i; break; } if(f1 != -1) { for(int i=f1+1;i<=N;i++) if(S[i] != T2[i-1]) { ok ^= 2; break; } } if(ok == 3 && !strcmp(T1+1, T2+1)) ok = 1; T1[N/2+1] = T2[N/2+1] = 0; if(ok == 0) { puts("NOT POSSIBLE"); return; } else if(ok == 1) printf("%s\n", T1+1); else if(ok == 2) printf("%s\n", T2+1); else puts("NOT UNIQUE"); } int main(){ int Tc = 1; // scanf("%d\n", &Tc); for(int tc=1;tc<=Tc;tc++){ solve(); } return 0; }

Compilation message (stderr)

friends.cpp: In function 'void solve()':
friends.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
friends.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", S+1);
  ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...