Submission #156709

#TimeUsernameProblemLanguageResultExecution timeMemory
156709junodeveloperThree Friends (BOI14_friends)C++14
100 / 100
56 ms12004 KiB
#include <bits/stdc++.h> #define sz(x) ((int)x.size()) #define all(x) (x).begin(), (x).end() #define fi first #define se second using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; int n; char s[2000010]; bool multi; string solve() { string ret=""; int i,j=-1,cnt=0; bool chk=true; for(i=0;i<=n/2;i++) { cnt+=s[i]==s[i+n/2]; } for(i=0;i<=n/2;i++) { cnt-=s[i]==s[i+n/2]; if(cnt==n/2) { if(j!=-1) { //s[j]==s[j+1],s[j+1]==s[j+2],...,s[i-1]==s[i] if(!chk) { multi=true; break; } } j=i; chk=true; } cnt+=s[i]==s[i+n/2+1]; chk&=s[i]==s[i+1]; } if(j==-1) return ret; for(i=0;i<n;i++) { if(i==j)continue; ret+=s[i]; } ret.erase(ret.begin()+n/2,ret.end()); return ret; } int main() { scanf("%d%s",&n,s); if(n%2==0){ puts("NOT POSSIBLE"); return 0; } int i; string a=solve(); if(multi) { puts("NOT UNIQUE"); return 0; } for(i=0;i<n/2;i++) swap(s[i],s[n-i-1]); string b=solve(); if(multi) { puts("NOT UNIQUE"); return 0; } reverse(b.begin(),b.end()); if(a.empty() && b.empty()) { puts("NOT POSSIBLE"); } else if(a.empty()) { printf("%s",b.c_str()); } else if(b.empty()) { printf("%s", a.c_str()); } else { if(a==b) printf("%s",a.c_str()); else puts("NOT UNIQUE"); } return 0; }

Compilation message (stderr)

friends.cpp: In function 'int main()':
friends.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%s",&n,s);
  ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...