제출 #31923

#제출 시각아이디문제언어결과실행 시간메모리
31923chonka세 명의 친구들 (BOI14_friends)C++98
100 / 100
123 ms27320 KiB
#include<iostream> #include<stdio.h> #include<string> using namespace std ; #define MAXN 2000007 int n ; string a ; int pref[ MAXN ] ; int suff[ MAXN ] ; bool f ( string s ) { int i ; int pos = 0 ; int br = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( a[ i ] == s[ pos ] ) { pos ++ ; } if ( pos == ( n / 2 ) ) { br ++ ; pos = 0 ; } } return ( br == 2 ) ; } void input ( ) { cin >> n ; cin >> a ; } void solve ( ) { if ( ( n % 2 ) == 0 ) { cout << "NOT POSSIBLE\n" ; return ; } int i ; int pos = ( n / 2 ) ; string x , y ; x.clear ( ) ; y.clear ( ) ; for ( i = 0 ; i < pos ; i ++ ) { x += a[ i ] ; } for ( i = pos + 1 ; i < n ; i ++ ) { y += a[ i ] ; } if ( x == y ) { cout << x << "\n" ; return ; } if ( f ( x ) == true && f ( y ) == true ) { cout << "NOT UNIQUE\n" ; } else if ( f ( x ) == true ) { cout << x << "\n" ; } else if ( f ( y ) == true ) { cout << y << "\n" ; } else { cout << "NOT POSSIBLE\n" ; } } int main ( ) { input ( ) ; solve ( ) ; return 0 ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...