제출 #998622

#제출 시각아이디문제언어결과실행 시간메모리
998622kirilchay세 명의 친구들 (BOI14_friends)C++17
35 / 100
42 ms35572 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back const ll MOD=1e9+7; const ll L=79; const ll N =2e6+7; ll h[N+2],hd[N+2]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; cin >> n; string s ; cin >> s; h[0]=1; for(ll i=1;i<=N;i++) { h[i]=(h[i-1]*L)%MOD; } hd[0]=0; for(ll i=1;i<=n;i++) { hd[i]=(((s[i-1]*h[i-1])%MOD)+hd[i-1])%MOD; } ll sm = 0; string ss; for(ll i=1;i<=n && sm < 2;i++) { if(i<=n/2+1){ ll a=1, b=i-1, c=n/2+2, d=n/2+i; ll a2=i+1, b2=n/2+1, c2=n/2+1+i, d2=n; if((((hd[b]-hd[a-1]+MOD)%MOD)*h[N-a])%MOD==(((hd[d]-hd[c-1]+MOD)%MOD)*h[N-c])%MOD && (((hd[b2]-hd[a2-1]+MOD)%MOD)*h[N-a2])%MOD==(((hd[d2]-hd[c2-1]+MOD)%MOD)*h[N-c2])%MOD) {sm++;ss=s.substr(n/2+1,n/2);} } else{ ll a=1, b=i-(n/2+1), c=n/2+1, d=n/2+(i-(n/2+1)); ll a2=i-(n/2+1)+1, b2=n/2, c2=n/2+(i-(n/2+1))+2, d2=n; if((((hd[b]-hd[a-1]+MOD)%MOD)*h[N-a])%MOD==(((hd[d]-hd[c-1]+MOD)%MOD)*h[N-c])%MOD && (((hd[b2]-hd[a2-1]+MOD)%MOD)*h[N-a2])%MOD==(((hd[d2]-hd[c2-1]+MOD)%MOD)*h[N-c2])%MOD) {sm++;ss=s.substr(0,n/2);} } } if(sm==0)cout<<"NOT POSSIBLE"; else if(s[0]!=s[1] && sm>1)cout<<"NOT UNIQUE"; else cout<<ss; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...