제출 #930745

#제출 시각아이디문제언어결과실행 시간메모리
930745Pwo세 명의 친구들 (BOI14_friends)C++17
0 / 100
36 ms6052 KiB
#include <bits/stdc++.h> using namespace std; int32_t main() { int n; cin >> n; string s; cin >> s; if (n % 2 == 0) { cout << "NOT POSSIBLE"; return 0; } int mp1[26]{}, mp2[26]{}; int l = (n - 1) / 2; for (int i = 0; i < n; i++) { int chr = (s[i] - 'A'); if (i < l) mp1[chr]++; else mp2[chr]++; } int d1 = 0; for (int i = 0; i < 26; i++) d1 += abs(mp1[i] - mp2[i]); fill(mp1, mp1 + 26, 0); fill(mp2, mp2 + 26, 0); l = (n + 1) / 2; for (int i = 0; i < n; i++) { int chr = (s[i] - 'A'); if (i < l) mp1[chr]++; else mp2[chr]++; } int d2 = 0; for (int i = 0; i < 26; i++) d2 += abs(mp1[i] - mp2[i]); if (d1 == 1 && d2 == 1) cout << "NOT UNIQUE"; else if (d1 == 1) cout << s.substr(0, (n - 1) / 2); else if (d2 == 1) cout << s.substr((n + 1) / 2, (n - 1) / 2); else cout << "NOT POSSIBLE"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...