Submission #549883

#TimeUsernameProblemLanguageResultExecution timeMemory
549883PherokungThree Friends (BOI14_friends)C++14
0 / 100
14 ms9520 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long const ll mod = 1e9+7, p = 10007; ll n,pw[200005],ans=-1,l[200005],r[200005],val; char s[200005]; ll mul(ll a,ll b) {return (a*b) % mod;} ll add(ll a,ll b) {return (a+b) % mod;} ll sub(ll a,ll b) {return (a-b+mod) % mod;} int main(){ scanf("%d%s",&n,s+1); if(!(n%2)){ printf("NOT POSSIBLE"); return 0; } pw[0] = 1; for(int i=1;i<=n;i++) pw[i] = mul(pw[i-1],p); val = 0; for(int i=1;i<=n;i++){ val = mul(val,p), val = add(val,(s[i]-'A'+1)); l[i] = val; } val = 0; for(int i=n;i>=1;i--){ val = add(val,mul((s[i]-'A'+1),pw[n-i])); r[i] = val; } for(int i=1;i<=n;i++){ ll L = n/2, R = n/2+2, M = n/2+1; if(i <= L){ val = sub(l[M],mul(l[i],pw[M-i])); val = add(mul(l[i-1],pw[M-i]),val); if(val == r[R]){ if(ans == -1) ans = i; else{ printf("NOT UNIQUE"); return 0; } } } else if(i == M){ if(l[L] == r[R]){ if(ans == -1) ans = i; else{ printf("NOT UNIQUE"); return 0; } } } else if(i >= R){ val = sub(l[i-1],mul(l[M-1],pw[i-M])); ll xxx = val; val = add(val,mul(r[i+1],pw[i-M])); if(l[L] == val){ if(ans == -1) ans = i; else{ printf("NOT UNIQUE"); return 0; } } } } if(ans == -1) printf("NOT POSSIBLE"); else{ ll cnt = n/2, pos = 1; while(cnt){ if(pos != ans){ printf("%c",s[pos]); cnt--; } pos++; } } }

Compilation message (stderr)

friends.cpp: In function 'int main()':
friends.cpp:12:10: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   12 |  scanf("%d%s",&n,s+1);
      |         ~^    ~~
      |          |    |
      |          int* long long int*
      |         %lld
friends.cpp:54:7: warning: unused variable 'xxx' [-Wunused-variable]
   54 |    ll xxx = val;
      |       ^~~
friends.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  scanf("%d%s",&n,s+1);
      |  ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...