This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
using namespace std;
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; i++)
#define pb push_back
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef long long ll;
int n,m;
string u;
int main() {
cin >> n; m = (n - 1) / 2;
cin >> u;
int numberEqual = 0;
vi cands;
rep(i,1,m+1) if (u[i] == u[i + m]) numberEqual++;
if (numberEqual == m) cands.pb(0);
rep(skip, 1, m) {
if (u[skip] == u[skip + m]) numberEqual--;
if (u[skip - 1] == u[skip + m]) numberEqual++;
if (numberEqual == m) cands.pb(skip);
}
numberEqual = 0;
rep(i,0,m) if (u[i] == u[i + m + 1]) numberEqual++;
if (numberEqual == m) cands.pb(m);
rep(skip, m + 1, n) {
if (u[skip] == u[skip - m - 1]) numberEqual--;
if (u[skip - 1] == u[skip - m - 1]) numberEqual++;
if (numberEqual == m) cands.pb(skip);
}
if (cands.size() == 0) {
cout << "NOT POSSIBLE\n";
}
else if (cands.size() > 1) {
cout << "NOT UNIQUE\n";
}
else {
int ans = cands[0];
vector<char> k;
int i = -1;
while (k.size() < m) {
i++;
if (i == ans) continue;
k.pb(u[i]);
}
rep(i,0,m) cout << k[i];
cout << endl;
}
}
Compilation message (stderr)
friends.cpp: In function 'int main()':
friends.cpp:51:21: warning: comparison of integer expressions of different signedness: 'std::vector<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
51 | while (k.size() < m) {
| ~~~~~~~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |