Submission #397001

#TimeUsernameProblemLanguageResultExecution timeMemory
397001lycThree Friends (BOI14_friends)C++14
100 / 100
14 ms7084 KiB
#include <bits/stdc++.h> using namespace std; #define TRACE(x) cerr << #x << " :: " << x << endl #define _ << " " << #define SZ(x) (int)(x).size() #define ALL(x) (x).begin(),(x).end() #define FOR(i,a,b) for(int i=(a);i<=(b);++i) #define RFOR(i,a,b) for (int i=(a);i>=(b);--i) const int mxN = 2e6+5; int N, cnt; string S, a1, a2; string solve() { int m = N/2, l = -1, r = m+1, ok; ok = 1; FOR(i,0,m-1){ ok &= S[i] == S[i+m+1]; if (ok) l = i; else break; } ok = 1; RFOR(i,m,0){ ok &= S[i] == S[i+m]; if (ok) r = i; else break; } TRACE(l _ r); if (l+2 >= r) return S.substr(m+1,N-m-1); return ""; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> N >> S; a1 = solve(); reverse(ALL(S)); a2 = solve(); reverse(ALL(a2)); if (!SZ(a1) && !SZ(a2)) cout << "NOT POSSIBLE" << '\n'; else if (SZ(a1) && SZ(a2) && a1 != a2) cout << "NOT UNIQUE" << '\n'; else cout << (SZ(a1) ? a1 : a2) << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...