Submission #154440

#TimeUsernameProblemLanguageResultExecution timeMemory
154440brcodeThree Friends (BOI14_friends)C++14
100 / 100
142 ms9164 KiB
#include <iostream> using namespace std; string res; string res2; bool ans1 = true; bool ans2 = true; int main(){ int n; cin>>n; string s; cin>>s; int mid = (s.length()+1)/2; int sz = (s.length()-1)/2; s='#'+s; int temp = mid+1; bool ok = false; int j = 1; int cnt = 1; while(cnt<=sz){ if(s[j]!=s[temp]){ if(ok){ ans1= false; break; }else{ ok = true; j++; } }else{ temp++; j++; cnt++; } } ok = false; temp= mid; j=1; cnt = 1; while(cnt<=sz){ // cout<<s[j]<<" "<<s[temp]<<endl; if(s[j]!=s[temp]){ if(ok){ ans2 = false; break; }else{ ok = true; temp++; } }else{ temp++; j++; cnt++; } } // cout<<ans1<<" "<<ans2<<endl; if((!ans1 && !ans2)||s.length()%2 == 1){ cout<<"NOT POSSIBLE"<<endl; }else if(!ans2){ for(int i=mid+1;i<s.length();i++){ res+=s[i]; } cout<<res<<endl; }else if(!ans1){ for(int i=1;i<=sz;i++){ res+=s[i]; } cout<<res<<endl; }else{ // cout<<res<<" "<<res2<<endl; res=""; res2=""; for(int i=mid+1;i<s.length();i++){ // cout<<s[i]<<endl; res+=s[i]; } for(int i=1;i<=sz;i++){ res2+=s[i]; } if(res == res2){ cout<<res<<endl; }else{ cout<<"NOT UNIQUE"<<endl; } } }

Compilation message (stderr)

friends.cpp: In function 'int main()':
friends.cpp:65:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=mid+1;i<s.length();i++){
                         ~^~~~~~~~~~~
friends.cpp:78:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
          for(int i=mid+1;i<s.length();i++){
                          ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...