# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
398742 | YaserFaisal | Three Friends (BOI14_friends) | C++17 | 1100 ms | 18380 KiB |
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
int MOD = 1e9+7 ;
int freq[200] ;
vector < int > v[200] ;
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n ; cin >> n ;
string s ; cin >> s ;
for ( int i = 0 ; i < n ; i++ )
{
freq[s[i]]++ ;
v[s[i]].push_back(i) ;
}
char x ;
int odd = 0 ;
for ( int i = 'A' ; i <= 'Z' ; i++ )
{
if ( freq[i] % 2 )
{
odd++ ;
x = i ;
}
}
if ( odd != 1 || n % 2 == 0 )
{
cout << "NOT POSSIBLE" ;
return 0 ;
}
string ans = "-" ;
for ( int i = 0 ; i < v[x].size() ; i++ )
{
string g = s ;
g.erase(g.begin()+v[x][i]) ;
string a = (g.substr(0,n/2)) , b = (g.substr(n/2,n/2)) ;
if ( a == b )
{
if ( ans != "-" )
{
cout << "NOT UNIQUE" ;
return 0 ;
}
ans = a ;
}
}
if ( ans == "-" ) ans = "NOT POSSIBLE" ;
cout << ans ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |