Submission #943338

#TimeUsernameProblemLanguageResultExecution timeMemory
943338Darren0724Three Friends (BOI14_friends)C++17
100 / 100
8 ms7680 KiB
#include <bits/stdc++.h> using namespace std; #define LCBorz ios_base::sync_with_stdio(false); cin.tie(0); #define all(x) x.begin(), x.end() #define endl '\n' const int N=200005; const int INF=1e9; string cmp(string a,string b){ if(a.size()>b.size())swap(a,b); int bad=0; int j=0; int n=a.size(); for(int i=0;i<n;i++){ while(j<b.size()&&a[i]!=b[j]){ bad++; j++; } j++; } return (bad<=1?a:""); } int32_t main() { LCBorz; int n;cin>>n; string s;cin>>s; string a=cmp(s.substr(0,n/2),s.substr(n/2,n-n/2)); string b=cmp(s.substr(0,n/2+1),s.substr(n/2+1,n-n/2)); if(n%2==0||(a.size()==0&&b.size()==0)){ cout<<"NOT POSSIBLE"<<endl; return 0; } if(a.size()!=0&&b.size()!=0&&a!=b){ cout<<"NOT UNIQUE"<<endl; return 0; } cout<<(a.size()?a:b)<<endl; return 0; }

Compilation message (stderr)

friends.cpp: In function 'std::string cmp(std::string, std::string)':
friends.cpp:14:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |         while(j<b.size()&&a[i]!=b[j]){
      |               ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...