제출 #21830

#제출 시각아이디문제언어결과실행 시간메모리
21830ngkan146세 명의 친구들 (BOI14_friends)C++14
35 / 100
13 ms44344 KiB
#include <bits/stdc++.h> using namespace std; string s; int n; int ans = 0; void no(){ cout << "NOT POSSIBLE"; exit(0); } int l[5000005],r[5000005], ansPOS; vector <int> poss; void check(){ for(int i=n/2;i<n-1;i++){ if (s[i-n/2] == s[i]) l[i] = l[i-1] + 1; else l[i] = - (int)1e9; } for(int i=n-1;i>n/2;i--) if (s[i-n/2-1] == s[i]) r[i] = r[i+1] + 1; else r[i] = - (int) 1e9; for(int i=n/2;i<n;i++){ if (l[i-1] + r[i+1] == n/2) ans++, ansPOS = i, poss.push_back(i); } for(int i=0;i<n/2;i++){ if (s[i] == s[i+n/2+1]) l[i] = (i ? l[i-1] : 0) + 1; else l[i] = -(int) 1e9; } r[n/2+1] = 0; for(int i=n/2;i>=1;i--){ if (s[i] == s[i+n/2]) r[i] = r[i+1] + 1; else r[i] = -(int) 1e9; } for(int i=0;i<n/2;i++){ if ((i?l[i-1]:0) + r[i+1] == n/2) ans++, ansPOS = i, poss.push_back(i); } } int main(){ iostream::sync_with_stdio(0); cin >> n >> s; if (n%2==0) no(); check(); int cnt = 0; if (!ans) no(); else{ bool ok = 1; sort(poss.begin(),poss.end()); for(int i=0;i<(int)poss.size()-1;i++){ if (abs(poss[i]-poss[i+1]) != 1 || s[poss[i]]!=s[poss[i+1]]) ok = 0; } if (!ok) cout << "NOT UNIQUE"; else{ for(int i=0;i<n;i++) if (cnt<n/2 && i != ansPOS) cnt++, cout << s[i]; } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...