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>
#define el '\n'
#define fi first
#define sc second
#define int ll
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
const int mod=1e9+7;
const int N=1e5+11;
string s, s1="", s2="";
int n;
void sol()
{
cin >> n >> s;
s=" "+s;
if(n%2==0)
{
cout << "NOT POSSIBLE";
return;
}
else
{
int i=1, j=n/2+2, ans=0, ch=0;
while(i<=n/2+1)
{
if(ch==2) break;
if(s[i]==s[j]) s1+=s[i], i++, j++;
else i++, ch++;
}
if(ch<=1) ans++;
i=1, j=n/2+1, ch=0;
while(i<=n/2)
{
if(ch==2) break;
if(s[i]==s[j]) s2+=s[j], i++, j++;
else j++, ch++;
}
if(ch<=1) ans++;
string ss=s1;
if(s2.size()==n/2) ss=s2;
if(ans==2 && s1!=s2) cout << "NOT UNIQUE";
else if(ans>=1) cout << ss;
else cout << "NOT POSSIBLE";
}
}
signed main()
{
// freopen("divisor.INP", "r", stdin);
// freopen("divisor.OUT", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin >> t;
while(t--)
{
sol();
}
}
Compilation message (stderr)
friends.cpp: In function 'void sol()':
friends.cpp:44:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
44 | if(s2.size()==n/2) ss=s2;
| ~~~~~~~~~^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |