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 LL long long
#define INF INT_MAX
#define output for(int i=0;i<sizex;i++) { for(int j=0;j<sizey;j++) { cout << moveChart[i][j] << " "; }cout<<endl; }cout<<endl;
const int maxN = 2000001;
int N; string s;
bool solve( string a, string b ){
// cout << a << " " << b << endl;
int i=0, j=0;
bool flag = true;
while( i < a.length() && j < b.length() ){
if( a[i] == b[j] ){ i++; j++; }
else if( flag ){
flag = false; i++;
}else return false;
}
return true;
}
int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
while( cin >> N >> s ){
if( !( N & 1 ) ){ cout << "NOT POSSIBLE" << endl; continue; }
string S, X;
bool resA, resB;
S = s.substr( 0, N/2 ); X = s.substr( N/2, N );
resA = solve( X, S );
S = s.substr( 0, N/2+1 ); X = s.substr( N/2+1, N );
resB = solve( S, X );
if( resA && resB ){
if( s.substr( 0, N/2 ) == s.substr( N/2+1, N ) ) resB = false;
}
if( resA && resB ) cout << "NOT UNIQUE" << endl;
else if( resA ) cout << s.substr( 0, N/2 ) << endl;
else if( resB ) cout << s.substr( N/2+1, N ) << endl;
else cout << "NOT POSSIBLE" << endl;
break;}
}
Compilation message (stderr)
friends.cpp: In function 'bool solve(std::__cxx11::string, std::__cxx11::string)':
friends.cpp:17:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while( i < a.length() && j < b.length() ){
~~^~~~~~~~~~~~
friends.cpp:17:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while( i < a.length() && j < b.length() ){
~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |