Submission #125437

#TimeUsernameProblemLanguageResultExecution timeMemory
125437wasylThree Friends (BOI14_friends)C++11
100 / 100
19 ms9112 KiB
#include <bits/stdc++.h> using namespace std; constexpr int nax = 2e6 + 1; int n; string s; pair< bool, string > spr(const string& a, const string& b) { //cerr << a << ' ' << b << ' '; int pt = 0; for (int i = 0; i < a.size(); ++i) if (pt < b.size() and a[i] == b[pt]) ++pt; //cerr << pt << '\n'; if (pt < b.size()) return {false, ""}; else return {true, b}; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> s; if (n % 2 == 0) return cout << "NOT POSSIBLE" << '\n', 0; int d = (n - 1) / 2; pair< bool, string > p, q; p = spr(s.substr(0, d + 1), s.substr(d + 1, d)); q = spr(s.substr(d, d + 1), s.substr(0, d)); if (p.first and q.first and (p.second != q.second)) return cout << "NOT UNIQUE" << '\n', 0; if (not p.first) swap(p, q); if (not p.first) cout << "NOT POSSIBLE" << '\n'; else cout << p.second << '\n'; }

Compilation message (stderr)

friends.cpp: In function 'std::pair<bool, std::__cxx11::basic_string<char> > spr(const string&, const string&)':
friends.cpp:13:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < a.size(); ++i)
                     ~~^~~~~~~~~~
friends.cpp:14:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (pt < b.size() and a[i] == b[pt])
             ~~~^~~~~~~~~~
friends.cpp:18:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (pt < b.size()) return {false, ""};
         ~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...