Submission #832524

#TimeUsernameProblemLanguageResultExecution timeMemory
832524vjudge1Three Friends (BOI14_friends)C++17
100 / 100
47 ms8144 KiB
#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)

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