# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
968753 | youssef_3breheem | Three Friends (BOI14_friends) | C++17 | 30 ms | 5448 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>
#include <string>
#include <vector>
using namespace std;
bool isPossible(const string& u) {
if (u.size() % 2 != 0) // If the length of U is odd, it's impossible to create S
return false;
string t = u.substr(0, u.size() / 2); // Split U into two equal parts to form T
string s;
// Iterate through all possible positions to split T into two copies of S
for (int i = 1; i < t.size(); ++i) {
string s1 = t.substr(0, i);
string s2 = t.substr(i);
string reconstructedU = s2 + s1 + s2; // Reconstruct U using the two copies of S
if (reconstructedU == u) { // If the reconstructed U matches the given U
if (s.empty()) { // If s is empty, store the current value of S
s = s1;
} else if (s != s1) { // If s is not empty and doesn't match the current value of S, S is not unique
return false;
}
}
}
return !s.empty(); // If S is not empty, it's possible to create S and it's unique
}
int main() {
int n;
cin >> n;
string u;
cin >> u;
if (!isPossible(u)) {
cout << "NOT POSSIBLE" << endl;
} else {
cout << (isPossible(u) ? "NOT UNIQUE" : u) << endl;
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |