제출 #44319

#제출 시각아이디문제언어결과실행 시간메모리
44319rajarshi_basu세 명의 친구들 (BOI14_friends)C++14
0 / 100
122 ms9316 KiB
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>

using namespace std;
 
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define ii pair<int,int>
#define mp(a,b) make_pair(a,b)

#define null NULL;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int all[26];
  FOR(i,26)all[i] = 0;
  FOR(i,n)all[s[i]-'A']++;
  int pos = -1;
  FOR(i,26){
    if(all[i]%2 == 1){
      if(pos == -1)pos = i;
      else{
       // cout<<pos<<endl;
        cout<<"NOT POSSIBLE"<<endl;
        return 0;
      }
    }
  }
  cout<<pos<<endl;
  if(pos == -1){
    cout<<"NOT POSSIBLE"<<endl;
    return 0;
  }
 // cout << "Sdsdf"<<endl;

  string res;
  char cc = 'A' + pos;
  bool cs3 = false;
  {
    string ss = "";
    FOR(i,n){
      if(i==n/2)continue;
      ss+=s[i];
    }
    //cout <<ss<<endl;
    string s1 = "";
    FOR(i,n/2)s1+=ss[i];
    s1+=s1;
   // cout<<s1<<endl;
    cs3 = (s1 == ss);
    if(cs3)res = s1;
   // cout<<"MC"<<cs3<<endl;
  }

  //cs4 somewhere else

  int cnt1 = 0;
  int cnt2 = 0;
  FOR(i,n/2){
    if(s[i] == cc)cnt1++;
    if(s[i+n/2+1] == cc)cnt2++;
  }

 //cout << cnt1 <<  " " <<cnt2<<endl;

    bool kk1  =false;bool kk2 = false;

  if(cnt1 > cnt2){
    string s1 = "";kk1= true;
    string s2 = "";
    FOR(i,n/2+1){
      s1+=s[i];
      if(i!=n/2)s2+=s[i+n/2+1];
    }
  
   // cout << s1<<"  "<<s2 <<endl;
    int ptr1=0;int ptr2 = 0;
    bool ok1 = 0;
    FOR(i,n/2){
      if(s1[i+ok1]!=s2[i]){
        if(ok1){
          kk1  = false;
        }else{
          ok1 = true;
        }
      }
    }
    if(kk1)res = s2;
  }else{
    string s1 = "";
    string s2 = "";
    kk2= true;
    FOR(i,n/2+1){
      if(i!=n/2)s1+=s[i];
      s2+=s[i+n/2];
    }
  //  cout << s1 << " " <<s2<<1<<endl;
    bool ok1 = 0;
    FOR(i,n/2){
      if(s1[i]!=s2[i+ok1]){
        if(ok1){
          kk2  = false;
        }else{
          ok1 = true;
        }
      }
    }
    if(kk2)res  = s1;
   // cout << kk2 <<endl;

  }

  if((kk1 && kk2) || (kk1 && cs3)){// || (kk2 && cs3)){
    cout  << "NOT UNIQUE"<<endl;//return -1;
  }else if(cs3 || kk1 || kk2){
    cout << res <<endl;//cout << cs3 <<kk1<<kk2<<endl;
  }else{
    cout << "NOT POSSIBLE"<<endl;// return -1;
  }





}

컴파일 시 표준 에러 (stderr) 메시지

friends.cpp: In function 'int main()':
friends.cpp:84:9: warning: unused variable 'ptr1' [-Wunused-variable]
     int ptr1=0;int ptr2 = 0;
         ^~~~
friends.cpp:84:20: warning: unused variable 'ptr2' [-Wunused-variable]
     int ptr1=0;int ptr2 = 0;
                    ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...