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 ;
const int MAX = 2e6 + 10 ;
int arr[MAX] ;
int n ;
string s ;
bool check(string s2 , int l , int r)
{
int idx = 0 ;
int rem = 1 ;
for(int i = l ; i <= r && idx < s2.size() ; ++i)
{
if(s[i] == s2[idx])
++idx ;
else
rem-- ;
}
return (idx == s2.size() && rem >= 0) ;
}
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n ;
cin>>s ;
if(n%2 == 0)
return cout<<"NOT POSSIBLE\n" , 0 ;
bool flag1 = check(s.substr(0 , n/2) , n/2 , n-1) ;
bool flag2 = check(s.substr(n-n/2 , n/2) , 0 , n/2) ;
if(!flag1 && !flag2)
cout<<"NOT POSSIBLE\n" ;
else if(flag1 && flag2 && s.substr(0 , n/2) != s.substr(n-n/2 , n/2))
cout<<"NOT UNIQUE\n" ;
else if(flag1)
cout<<s.substr(0 , n/2)<<"\n" ;
else
cout<<s.substr(n-n/2 , n/2) ;
return 0 ;
}
Compilation message (stderr)
friends.cpp: In function 'bool check(std::string, int, int)':
friends.cpp:16:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for(int i = l ; i <= r && idx < s2.size() ; ++i)
| ~~~~^~~~~~~~~~~
friends.cpp:23:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | return (idx == s2.size() && rem >= 0) ;
| ~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |