# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
832524 | vjudge1 | Three Friends (BOI14_friends) | C++17 | 47 ms | 8144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
using namespace std;
int n;
bool canFirst, canSecond;
string s, t1, t2;
bool canAddLetter(const string &t) {
bool added = false;
for (int i = 0; i < t.size(); i++) {
if (!added && t[i] != s[i]) added = true;
if (added && t[i] != s[i + 1]) return false;
}
return true;
}
int main() {
cin >> n >> s;
if (n & 1) {
n >>= 1;
t1 = s.substr(0, n); t2 = s.substr(n + 1);
canFirst = canAddLetter(t1 + t1); canSecond = canAddLetter(t2 + t2);
if (canFirst && canSecond && t1 == t2) cout << t1;
else if (canFirst && canSecond) cout << "NOT UNIQUE";
else if (canFirst) cout << t1;
else if (canSecond) cout << t2;
else cout << "NOT POSSIBLE";
}
else cout << "NOT POSSIBLE";
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |