Submission #72888

#TimeUsernameProblemLanguageResultExecution timeMemory
72888VardanyanThree Friends (BOI14_friends)C++14
100 / 100
154 ms16052 KiB
//#pragma GCC optimize "-O3" #include <bits/stdc++.h> using namespace std; bool check(string a,string b){ if(a.length()<b.length()) swap(a,b); int i = 0; int j = 0; bool f = false; while(i<a.length()){ if(a[i]!=b[j] && f) return false; if(a[i]!=b[j]){ f = true; i++; continue; } i++; j++; } return true; } int main() { int n; string s; cin>>n>>s; if(n%2 == 0){ cout<<"NOT POSSIBLE"<<endl; return 0; } string s1; for(int i = 0;i<n/2;i++) s1+=s[i]; string s2; for(int i = n/2+1;i<n;i++) s2+=s[i]; string s3; for(int i = 0;i<=n/2;i++) s3+=s[i]; string s4; for(int i = n/2;i<n;i++) s4+=s[i]; int c = check(s1,s4)+check(s2,s3); if(c == 0){ cout<<"NOT POSSIBLE"<<endl; return 0; } if(c == 1 || s1 == s2){ if(check(s1,s4)) cout<<s1<<endl; else cout<<s2<<endl; return 0; } cout<<"NOT UNIQUE"<<endl; return 0; }

Compilation message (stderr)

friends.cpp: In function 'bool check(std::__cxx11::string, std::__cxx11::string)':
friends.cpp:9:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(i<a.length()){
           ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...