제출 #1069360

#제출 시각아이디문제언어결과실행 시간메모리
1069360pera세 명의 친구들 (BOI14_friends)C++17
100 / 100
41 ms9240 KiB
#include<bits/stdc++.h>
using namespace std;
int main(){
   int n;
   cin >> n;
   string U;
   cin >> U;
   U = "$" + U;
   if(n % 2 == 0){
      cout << "NOT POSSIBLE" << '\n';
      return 0;
   }
   string Front , Back;
   for(int i = 1;i <= n / 2;i ++){
      Front += U[i];
   }
   for(int i = n / 2 + 2;i <= n;i ++){
      Back += U[i];
   }
   int t = 1 , cnt_front = 0;
   for(int i = n / 2 + 1;i <= n && t <= n / 2;i ++){
      if(U[i] == U[t]){
         ++t;
         continue;
      }
      ++cnt_front;
   }
   cnt_front += (t != n / 2 + 1) * 2;
   int cnt_back = 0;
   t = n;
   for(int i = n / 2 + 1;i >= 1 && t > n / 2 + 1;i --){
      if(U[i] == U[t]){
         --t;
         continue;
      }
      ++cnt_back;
   }
   cnt_back += (t != n / 2 + 1) * 2;
   if(cnt_front < 2 && cnt_back < 2 && Back != Front){
      printf("%s" , "NOT UNIQUE");
      return 0;
   }
   if(cnt_front < 2){
      printf("%s" , Front.c_str());
      return 0;
   }
   if(cnt_back < 2){
      printf("%s" , Back.c_str());
      return 0;
   }
   printf("%s" , "NOT POSSIBLE");
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...