Submission #394892

#TimeUsernameProblemLanguageResultExecution timeMemory
394892Nicholas_PatrickThree Friends (BOI14_friends)C++17
100 / 100
54 ms7180 KiB
#include <iostream> #include <string> using namespace std; bool valid(string& s, string& a){ int n=a.size(); bool miss=false; for(int i=0, j=0; i<s.size(); i++){ if(s[i]!=a[j]){ if(miss) return false; miss=true; }else{ j++; if(j==n) j=0; } } return true; } int main(){ int n; string s; cin>>n>>s; if(~n&1){ cout<<"NOT POSSIBLE"<<endl; return 0; } n>>=1; string a=s.substr(0, n), b=s.substr(n+1, n*2+1); if(valid(s, a)){ if(valid(s, b)){ if(a==b){ cout<<a<<endl; }else{ cout<<"NOT UNIQUE"<<endl; } }else{ cout<<a<<endl; } }else{ if(valid(s, b)){ cout<<b<<endl; }else{ cout<<"NOT POSSIBLE"<<endl; } } }

Compilation message (stderr)

friends.cpp: In function 'bool valid(std::string&, std::string&)':
friends.cpp:8:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  for(int i=0, j=0; i<s.size(); i++){
      |                    ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...