제출 #853156

#제출 시각아이디문제언어결과실행 시간메모리
853156NK_세 명의 친구들 (BOI14_friends)C++17
100 / 100
18 ms9776 KiB
// Success consists of going from failure to failure without loss of enthusiasm #include <bits/stdc++.h> using namespace std; #define nl '\n' #define pb push_back #define pf push_front #define mp make_pair #define f first #define s second #define sz(x) int(x.size()) template<class T> using V = vector<T>; using pi = pair<int, int>; using vi = V<int>; using vpi = V<pi>; using ll = long long; using pl = pair<ll, ll>; using vpl = V<pl>; using vl = V<ll>; using db = long double; template<class T> using pq = priority_queue<T, V<T>, greater<T>>; const int MOD = 1e9 + 7; const ll INFL = ll(1e17); const int LG = 18; int main() { cin.tie(0)->sync_with_stdio(0); int N; cin >> N; string S; cin >> S; if (N % 2 == 0) { cout << "NOT POSSIBLE" << nl; exit(0-0); } int M = (N - 1) / 2; auto tri = [&](string T) { int j = 0; for(int i = 0; i < N; i++) { if (j < 2*M && S[i] == T[j]) j++; } return j == 2 * M; }; string A = S.substr(0, M); string B = S.substr(N - M, M); if (A == B) B.back() = '|'; bool a = tri(A + A), b = tri(B + B); if (a && b) cout << "NOT UNIQUE" << nl; else if (a) cout << A << nl; else if (b) cout << B << nl; else cout << "NOT POSSIBLE" << nl; exit(0-0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...