제출 #180312

#제출 시각아이디문제언어결과실행 시간메모리
180312rzbt세 명의 친구들 (BOI14_friends)C++14
100 / 100
121 ms50168 KiB
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define F first #define S second #define all(x) x.begin(),x.end() #define MAXN 2000006 typedef long long ll; using namespace std; const ll MOD = 1e9+9; ll n; char s[MAXN]; ll hes[MAXN]; ll stepen[MAXN]; ll res=0; ll posl; vector<ll> svi; int main() { scanf("%lld", &n); if(!(n&1)){ printf("NOT POSSIBLE"); return 0; } scanf("%s",s); hes[0]=s[0]-'A'+1; stepen[0]=1; for(ll i=1;i<n;i++){ stepen[i]=(79*stepen[i-1])%MOD; hes[i]=(stepen[i]*(s[i]-'A'+1)+hes[i-1])%MOD; } for(ll i=0;i<n;i++){ if(i<(n>>1)){ ll th=hes[n>>1]-hes[i]; if(i!=0)th+=hes[i-1]*stepen[1]; th=(MOD+MOD+MOD+th)%MOD; th*=stepen[n/2]; th%=MOD; if(th==(MOD+hes[n-1]-hes[n>>1])%MOD){ res++,posl=i; svi.pb(th); } } if(i>(n>>1)){ ll th=hes[n-1]-hes[i]; th+=(hes[i-1]-hes[(n>>1)-1])*stepen[1]; th=(MOD+MOD+MOD+th)%MOD; //printf(" %lld %lld\n",th,(hes[(n>>1)-1]*stepen[(n>>1)+1])%MOD ); if(th==(hes[(n>>1)-1]*stepen[(n>>1)+1])%MOD ){ res++,posl=i; svi.pb(th); } } if(i==(n>>1)){ ll ta=hes[(n>>1)-1]; ll tb=(MOD+hes[n-1]-hes[(n>>1)])%MOD; //printf("%lld %lld %lld %lld",ta,tb,stepen[(n>>1)+1],(ta*stepen[(n>>1)+1])%MOD); if(tb==(ta*stepen[(n>>1)+1])%MOD){ res++,posl=i; svi.pb(tb); } } } if(res==0)printf("NOT POSSIBLE"); else{ for(int i=0;i<svi.size()-1;i++){ if(svi[i]!=svi[i+1]){ printf("NOT UNIQUE"); return 0; } } ll gran=(n>>1); for(ll i=0;i<gran;i++){ if(i==posl)gran++; else putchar(s[i]); } } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

friends.cpp: In function 'int main()':
friends.cpp:76:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<svi.size()-1;i++){
                     ~^~~~~~~~~~~~~
friends.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &n);
     ~~~~~^~~~~~~~~~~~
friends.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s",s);
     ~~~~~^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...