Submission #968753

#TimeUsernameProblemLanguageResultExecution timeMemory
968753youssef_3breheemThree Friends (BOI14_friends)C++17
0 / 100
30 ms5448 KiB
#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)

friends.cpp: In function 'bool isPossible(const string&)':
friends.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for (int i = 1; i < t.size(); ++i) {
      |                     ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...