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 <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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |