| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 391031 | shahriarkhan | Three Friends (BOI14_friends) | C++14 | 349 ms | 11184 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std ;
const int mx = 3e6 ;
int a[mx] , n ;
string s ;
long long gcd(long long a , long long b , long long &x , long long &y)
{
if(!a)
{
x = 0 , y = 1 ;
return b ;
}
long long x1 , y1 ;
long long d = gcd(b%a,a,x1,y1) ;
x = y1 - (b/a)*x1 ;
y = x1 ;
return d ;
}
long long modinverse(long long a , long long m)
{
long long x , y ;
long long g = gcd(a,m,x,y) ;
return (x%m + m)%m ;
}
void f(long long mod)
{
long long P = 1 , first = 0 , second = 0 , c_first = 0 , c_second = 0 , tot = 0 , div = modinverse(31,mod) ;
for(int i = 0 ; i <= (n/2) ; ++i)
{
if(i==(n/2)) c_first = first ;
first = (first + ((s[i]-'A'+1)*P)%mod)%mod ;
P = (P*31LL)%mod ;
}
P = 1 ;
for(int i = (n/2) ; i < n ; ++i)
{
second = (second + ((s[i]-'A'+1)*P)%mod)%mod ;
P = (P*31LL)%mod ;
}
P = 1 ;
for(int i = (n/2) + 1 ; i < n ; ++i)
{
c_second = (c_second + ((s[i]-'A'+1)*P)%mod)%mod ;
P = (P*31LL)%mod ;
}
P = 1 ;
for(int i = 0 ; i < (n/2) ; ++i)
{
tot = (tot + ((s[i]-'A'+1)*P)%mod)%mod ;
long long cur = (tot - ((s[i]-'A'+1)*P)%mod + (((first-tot+mod)%mod)*div)%mod + mod)%mod ;
if(cur==c_second) a[i] &= 1 ;
else a[i] = 0 ;
P = (P*31LL)%mod ;
}
tot = 0 , P = 1 ;
for(int i = n/2 ; i < n ; ++i)
{
tot = (tot + ((s[i]-'A'+1)*P)%mod)%mod ;
long long cur = (tot - ((s[i]-'A'+1)*P)%mod + (((second-tot+mod)%mod)*div)%mod + mod)%mod ;
if(cur==c_first) a[i] &= 1 ;
else a[i] = 0 ;
P = (P*31LL)%mod ;
}
}
int main()
{
int ans = -1 , cnt = 0 ;
scanf("%d",&n) ;
cin>>s ;
if(!(n&1))
{
puts("NOT POSSIBLE") ;
return 0 ;
}
for(int i = 0 ; i < n ; ++i) a[i] = 1 ;
long long cur = 1e9 + 7 ;
f(cur) ;
cur = 1e9 + 9 ;
f(cur) ;
for(int i = 0 ; i < n ; ++i)
{
if(a[i]) ans = i ;
cnt += a[i] ;
}
if(!cnt)
{
puts("NOT POSSIBLE") ;
}
else if(cnt==1)
{
for(int i = 0 ; i < (n/2) + (ans<(n/2)) ; ++i)
{
if(i==ans) continue ;
cout<<s[i] ;
}
cout<<endl ;
}
else
{
puts("NOT UNIQUE") ;
}
return 0 ;
}컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
