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;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
string s;
void solve(){
cin >> n;
if(n % 2 == 0){
cout << "NOT POSSIBLE\n";
return;
}
cin >> s;
int a = 0, b = 0, c = 0, d = 0;
for(int i = 0; i < n / 2; i++){
if(s[i] == s[i + n / 2])a++;
else break;
}
for(int i = 0; i < n / 2; i++){
if(s[i] == s[i + n / 2 + 1])b++;
else break;
}
for(int i = n - 1; i >= n / 2 + 1; i--){
if(s[i] == s[i - n / 2])c++;
else break;
}
for(int i = n - 1; i >= n / 2 + 1; i--){
if(s[i] == s[i - n / 2 - 1])d++;
else break;
}
if(max(b + c, a + d) > n / 2 || (b + c == n / 2 && a + d == n / 2))cout << "NOT UNIQUE\n";
else if(b + c < n / 2 && a + d < n / 2)cout << "NOT POSSIBLE\n";
else{
if(a + d == n / 2){
for(int i = 0; i < n / 2; i++)cout << s[i];
}
else{
for(int i = n / 2 + 1; i < n; i++)cout << s[i];
}
}
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int tc = 1;
//cin >> tc;
for(int tc1=1;tc1<=tc;tc1++){
// cout << "Case #" << tc1 << ": ";
solve();
}
}
Compilation message (stderr)
friends.cpp:53:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
53 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |