Submission #44341

#TimeUsernameProblemLanguageResultExecution timeMemory
44341rajarshi_basuThree Friends (BOI14_friends)C++14
0 / 100
124 ms9604 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(n%2 == 0){ cout<<"NOT POSSIBLE"<<endl; return 0; } string res; char cc = 'A' + pos; bool unq = true; 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 <<ss << s1 <<1<< endl; // cout<<s1<<endl; cs3 = (s1 == ss); if(cs3)res = s1; //cout <<cs3<<endl; if(cs3){ if(s[n/2] == s[n/2+1] || s[n/2 -1] == s[n/2]){ // cout<<"NOT UNIQUE"<<endl; //return 0; unq = false; } } // cout<<"MC"<<cs3<<endl; } bool kk1 =false;bool kk2 = false; { string s1 = "";kk1= true; string s2 = ""; FOR(i,n/2+1){ s1+=s[i]; if(i!=n/2)s2+=s[i+n/2+1]; } bool ok1 = 0; FOR(i,n/2){ if(s1[i+ok1]!=s2[i]){ if(ok1){ kk1 = false; }else{ ok1 = true; if(i>0 && s1[i] == s1[i-1]){ unq = false;//cout<<"NOT UNIQUE"<<endl;return 0; } if(i<n/2-1 && s1[i] == s1[i+1]){ unq = false;// cout<<"NOT UNIQUE"<<endl;return 0; } } } } if(cs3 && !ok1)kk1 = false; if(kk1)res = s2; } { 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(i>0 && s2[i] == s2[i-1]){ unq = false;// cout<<"NOT UNIQUE"<<endl;return 0; } if(i<n/2-1 && s2[i] == s2[i+1]){ unq = false;//cout<<"NOT UNIQUE"<<endl;return 0; } } } } if(cs3 &&! ok1)kk2= false; if(!ok1){ if(s[n-1] == s[n-2]){unq = false;}//cout<<"NOT UNIQUE"<<endl;return 0;} } if(kk2)res = s1; // cout << kk2 <<endl; } //cout << cs3<<kk1<<kk2<<endl; if((kk1 && kk2) || (kk1 && cs3)){//} || (kk2 && cs3)){ cout << "NOT UNIQUE"<<endl;//return -1; }else if(cs3 || kk1 || kk2 ){ if(unq)cout << res <<endl;//cout << cs3 <<kk1<<kk2<<endl; else cout<<"NOT UNIQUE"<<endl; }else{ cout << "NOT POSSIBLE"<<endl;// return -1; } }

Compilation message (stderr)

friends.cpp: In function 'int main()':
friends.cpp:43:8: warning: unused variable 'cc' [-Wunused-variable]
   char cc = 'A' + pos;
        ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...