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 int long long
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define int long long
using namespace std ;
mt19937 rng(time(0)) ;
const int maxn = 2e6 + 10 , pr[] = {71 , 73};
int sl(string a, string b){
int x = -1 ;
for(int i =0 ; i < a.size()-1 ; i++){
if(a[i] != b[i])break ;
x++;
}
int y = a.size() ;
for(int i= a.size() - 1; i >= 1; i--){
if(a[i] != b[i-1])break;
y--;
}
if(y-x <= 2){
return 1;
}
return 0 ;
}
signed main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n ;
string s;
cin >> n >> s ;
if(n % 2==0){
cout << "NOT POSSIBLE\n";
return 0 ;
}
s = " " + s;
string a1 , b1 , a2 ,b2 ;
for(int i = 1; i <= n/2 ;i++){
b2 += s[i] ;
a1 += s[i] ;
}
a1 += s[n/2 +1] ;
for(int i =n/2+2 ; i <= n; i++){
b1 += s[i] ;
a2 += s[i] ;
}
a2 = s[n/2+1] + a2 ;
int x = sl(a1 , b1) , y = sl(a2 , b2);
if(x==0 && y == 0){
cout << "NOT POSSIBLE\n";
return 0 ;
}
if(x==1 && y==1 && b1 != b2){
cout << "NOT UNIQUE\n";
return 0 ;
}
if(x==1){
cout << b1 << "\n" ;
}else{
cout << b2 << "\n" ;
}
}
Compilation message (stderr)
friends.cpp: In function 'long long int sl(std::string, std::string)':
friends.cpp:17:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int i =0 ; i < a.size()-1 ; i++){
| ~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |