This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author: hashman
* created:
**/
#include <bits/stdc++.h>
using namespace std;
string to_string(string s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() {
cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__);
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
if (n % 2 == 0) {
cout << "NOT POSSIBLE\n";
return 0;
}
auto ok = [&](string cnd) {
vector<int> gcnd(26);
for (char ch : cnd) {
gcnd[ch - 'A'] -= 2;
}
for (char ch : s) {
gcnd[ch - 'A']++;
}
if (count(gcnd.begin(), gcnd.end(), 1) != 1 || count(gcnd.begin(), gcnd.end(), 0) != 25) {
return false;
}
string res = cnd + cnd;
int j = -1;
for (char ch : res) {
bool found = false;
j++;
if (s[j] == ch) {
found = true;
}
while (j < n && s[j] != ch) {
++j;
if (j < n && s[j] == ch) {
found = true;
}
}
if (!found) {
return false;
}
}
return true;
};
string first, second;
for (int i = (n + 1) / 2; i < n; i++) {
first += s[i];
}
for (int i = 0; i < (n - 1) / 2; i++) {
second += s[i];
}
int cnt = ok(first) + ok(second);
if (cnt == 2) {
if (first == second) {
cout << first << '\n';
} else {
cout << "NOT UNIQUE\n";
}
} else if (cnt == 1) {
if (ok(first)) {
cout << first << '\n';
} else {
cout << second << '\n';
}
} else {
cout << "NOT POSSIBLE\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |