Submission #337669

#TimeUsernameProblemLanguageResultExecution timeMemory
337669Sho10Three Friends (BOI14_friends)C++14
100 / 100
13 ms8208 KiB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10 #define ll long long #define double long double #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #define all(a) (a).begin(), (a).end() #define f first #define s second #define pb push_back #define mp make_pair #define pi pair #define rc(s) return cout<<s,0 #define endl '\n' #define mod 1000000007 #define PI 3.14159265359 #define MAXN 100005 #define INF 1000000005 #define LINF 1000000000000000005ll #define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; ll n; string s; vector<string>ans; void calc(string a,string b){ ll cnt[3]; cnt[0]=cnt[1]=cnt[2]=0; while(cnt[0]<a.size()&&cnt[1]<b.size()){ if(a[cnt[0]]==b[cnt[1]]){ cnt[0]++; cnt[1]++; }else { cnt[2]++; cnt[1]++; } } if(cnt[2]>1){ return; } if(ans.empty()){ ans.pb(a); return; } if(ans[0]!=a){ ans.pb(a); return; } } int32_t main(){ CODE_START; cin>>n; cin>>s; if(n%2==0){ cout<<"NOT POSSIBLE"<<endl; return 0; } n/=2; calc(s.substr(0,n),s.substr(n,n+1)); calc(s.substr(n+1,n),s.substr(0,n+1)); if(ans.empty()){ cout<<"NOT POSSIBLE"<<endl; }else if(ans.size()==1){ cout<<ans[0]<<endl; }else { cout<<"NOT UNIQUE"<<endl; } }

Compilation message (stderr)

friends.cpp: In function 'void calc(std::string, std::string)':
friends.cpp:27:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 | while(cnt[0]<a.size()&&cnt[1]<b.size()){
      |       ~~~~~~^~~~~~~~~
friends.cpp:27:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 | while(cnt[0]<a.size()&&cnt[1]<b.size()){
      |                        ~~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...