# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
968753 | 2024-04-24T02:37:16 Z | youssef_3breheem | Three Friends (BOI14_friends) | C++17 | 30 ms | 5448 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 30 ms | 5448 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |