제출 #733314

#제출 시각아이디문제언어결과실행 시간메모리
733314Trunkty세 명의 친구들 (BOI14_friends)C++14
100 / 100
29 ms11248 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll int n; string u,a,b; bool pre[2000005],suf[2000005]; bool isa, isb; signed main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> u; if(n%2==0){ cout << "NOT POSSIBLE" << "\n"; return 0; } n /= 2; for(int i=0;i<n;i++){ a += u[i]; } for(int i=n+1;i<n*2+1;i++){ b += u[i]; } if(a==b){ cout << a << "\n"; return 0; } for(int i=0;i<n;i++){ if(i==0){ if(u[i]==b[i]){ pre[i] = true; } else{ pre[i] = false; } } else{ if(u[i]==b[i] and pre[i-1]){ pre[i] = true; } else{ pre[i] = false; } } } for(int i=n;i>0;i--){ if(i==n){ if(u[i]==b[i-1]){ suf[i] = true; } else{ suf[i] = false; } } else{ if(u[i]==b[i-1] and suf[i+1]){ suf[i] = true; } else{ suf[i] = false; } } } if(pre[n-1] or suf[1]){ isa = true; } else{ for(int i=0;i<n-1;i++){ if(pre[i] and suf[i+2]){ isa = true; break; } } } for(int i=n;i<2*n;i++){ if(i==n){ if(u[i]==a[i-n]){ pre[i] = true; } else{ pre[i] = false; } } else{ if(u[i]==a[i-n] and pre[i-1]){ pre[i] = true; } else{ pre[i] = false; } } } for(int i=2*n;i>n;i--){ if(i==2*n){ if(u[i]==a[i-n-1]){ suf[i] = true; } else{ suf[i] = false; } } else{ if(u[i]==a[i-n-1] and suf[i+1]){ suf[i] = true; } else{ suf[i] = false; } } } if(pre[2*n-1] or suf[n+1]){ isb = true; } else{ for(int i=n;i<2*n-1;i++){ if(pre[i] and suf[i+2]){ isb = true; break; } } } if(isa and isb){ cout << "NOT UNIQUE" << "\n"; } else{ if(isa){ cout << b << "\n"; } else if(isb){ cout << a << "\n"; } else{ cout << "NOT POSSIBLE" << "\n"; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...