Submission #423467

#TimeUsernameProblemLanguageResultExecution timeMemory
423467victoriadThree Friends (BOI14_friends)C++14
100 / 100
55 ms8204 KiB
#include <cmath> #include <cstdio> #include <iostream> #include <algorithm> #include <utility> #include <vector> #include <map> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); int n; string s; cin>>n>>s; vector<int>can(30,0); if(n%2==0){ cout<<"NOT POSSIBLE"; } else{ for(int i=0;i<n;i++){ can[s[i]-65]++; } int l=0; int us=-1; vector<char> a; int x,y; int p=-1; for(int i=0;i<n/2;i++){ if(s[i]==s[i+n/2]||s[i]==s[i+n/2+1]){ a.push_back(s[i]); if(s[i]==s[i+1]&& s[i]!=s[i+n/2]&& s[i+n/2+1]!=s[i+n/2+2]){ a.pop_back(); l++; } } else{ if(l==0){ l=1; p=i; } else{ l++; cout<<"NOT POSSIBLE"; break; } } } if(l<=1){ if(s[n/2]!=s[0] && s[n/2]==s[n-1])a.push_back(s[n/2]); if(a.size()!=n/2)cout<<"NOT POSSIBLE"; else{ vector<char>b; if(l==0){ for(int i=1;i<=n/2;i++){ if(s[i]==s[i+n/2])b.push_back(s[i]); else{ break; } } } bool j=true; if(b.size()==a.size()){ for(int i=0;i<n/2;i++){ if(a[i]!=b[i]){ j=false; cout<<"NOT UNIQUE"; break; } } } if(j){ for(int i=0;i<n/2;i++)cout<<a[i]; } } } } return 0; }

Compilation message (stderr)

friends.cpp: In function 'int main()':
friends.cpp:50:14: warning: comparison of integer expressions of different signedness: 'std::vector<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |   if(a.size()!=n/2)cout<<"NOT POSSIBLE";
      |      ~~~~~~~~^~~~~
friends.cpp:24:7: warning: unused variable 'us' [-Wunused-variable]
   24 |   int us=-1;
      |       ^~
friends.cpp:26:7: warning: unused variable 'x' [-Wunused-variable]
   26 |   int x,y;
      |       ^
friends.cpp:26:9: warning: unused variable 'y' [-Wunused-variable]
   26 |   int x,y;
      |         ^
friends.cpp:27:7: warning: variable 'p' set but not used [-Wunused-but-set-variable]
   27 |   int p=-1;
      |       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...