제출 #493986

#제출 시각아이디문제언어결과실행 시간메모리
493986goodluck2020세 명의 친구들 (BOI14_friends)C++14
0 / 100
26 ms24428 KiB
#include <bits/stdc++.h> #define task "friends" using namespace std; const int N = 1e6 + 10; int c, n, m, A[N], B[N], ans, res, tmp; bool L[N], R[N]; string S; void CALC() { L[0] = 1; R[n + 1] = 1; for(int i = 1; i <= n; i++) L[i] = min(L[i-1], (A[i] == B[i])); for(int i = n; i >= 1; i--) R[i] = min(R[i+1], (A[i] == B[i - 1])); for(int i = 1; i < n; i++) if(L[i-1] && R[i+1]) { ans++; res = tmp + i; } return; } void TruyVet(int k) { if(k > c/2) for(int i = 0; i < c/2; i++) cout << S[i]; else for(int i = c/2 + 1; i < c; i++) cout << S[i]; } int main() { /*if(fopen(task ".inp","r")) { freopen(task ".inp","r",stdin); freopen(task ".out","w",stdout); }*/ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> c >> S; if(c % 2 == 0) { cout << "NOT POSSIBLE"; return 0; } for(int i = 0; i <= c/2; i++) A[++n] = S[i] - 'A'; for(int i = c/2 + 1; i < c; i++) B[++m] = S[i] - 'A'; CALC(); for(int i = 0; i < c/2; i++) B[++m] = S[i] - 'A'; for(int i = c/2; i < c; i++) A[++n] = S[i] - 'A'; tmp = c/2; CALC(); if(ans == 1) TruyVet(res); else if(ans > 1) cout << "NOT UNIQUE"; else cout << "NOT POSSIBLE"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...