제출 #599256

#제출 시각아이디문제언어결과실행 시간메모리
599256Jomnoi세 명의 친구들 (BOI14_friends)C++17
100 / 100
29 ms5192 KiB
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2e6 + 5; char U[MAX_N]; int main() { cin.tie(nullptr)->sync_with_stdio(false); int N; cin >> N >> (U + 1); if(N % 2 == 0) { cout << "NOT POSSIBLE"; return 0; } int M = N / 2; int l = 1, r = M + 1, cnt = 0; bool frnt = false, bck = false; while(l <= M and r <= N) { if(U[l] == U[r]) { l++, r++; } else { cnt++; r++; } } if(cnt <= 1) { frnt = true; } l = 1, r = M + 2, cnt = 0; while(l <= M + 1 and r <= N) { if(U[l] == U[r]) { l++, r++; } else { cnt++; l++; } } if(cnt <= 1) { bck = true; } if(frnt == true and bck == true) { cnt = 0; for(int i = 1; i <= M; i++) { if(U[i] == U[M + 1 + i]) { cnt++; } } if(cnt == M) { for(int i = 1; i <= M; i++) { cout << U[i]; } } else { cout << "NOT UNIQUE"; } } else if(frnt == true) { for(int i = 1; i <= M; i++) { cout << U[i]; } } else if(bck == true) { for(int i = M + 2; i <= N; i++) { cout << U[i]; } } else { cout << "NOT POSSIBLE"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...