Submission #26462

#TimeUsernameProblemLanguageResultExecution timeMemory
26462WhipppedCreamSequence (BOI14_sequence)C++14
0 / 100
0 ms3000 KiB
#include <bits/stdc++.h> using namespace std; #define X first #define Y second #define pb push_back #define mp make_pair typedef pair<int, int> ii; typedef vector<int> vi; typedef vector< ii > vii; typedef long long L; typedef vector< L > vL; typedef vector< vL > vvL; typedef vector< vi > vvi; typedef vector< vii > vvii; const int inf = 1e9; const L inf8 = 1e18; const int maxn = 2e5 + 5; const int md = 1e9 + 7; void np() { puts("NOT POSSIBLE"); exit(0); } void nu() { puts("NOT UNIQUE"); exit(0); } void add(int &a, int b) { a += b; if(a>= md) a -= md; } void sub(int &a, int b) { a -= b; if(a< 0) a += md; } int mul(int a, int b) { return (1LL*a*b)%md; } int power(int a, int b) { if(b == 0) return 1; int x = power(a, b/2); int y = mul(x, x); if(b%2) y = mul(y, a); return y; } int inv(int a) { return power(a, md-2); } int Hash[maxn]; int val[26]; int magic; char s[maxn]; void calc_hash(int n) { for(int i = 0; i< 26; i++) val[i] = rand(); magic = rand(); for(int i = 0; i< n; i++) { add(Hash[i], i?Hash[i-1]:0); add(Hash[i], mul(power(magic, i), val[s[i]-'A'])); } } int find_hash(int a, int b) { int stand = Hash[b]; sub(stand, a?Hash[a-1]:0); stand = mul(stand, inv(power(magic, a))); return stand; } int main() { int n; scanf("%d", &n); scanf("%s", s); if(n%2 == 0 || n<= 2) np(); calc_hash(n); int A = find_hash(0, n/2-1); int B = find_hash(n/2+1, n-1); int a, b; a = b = 0; for(int i = n/2; i< n; i++) { int left = i>n/2?find_hash(n/2, i-1):0; int right = i+1<n?find_hash(i+1, n-1):0; right = mul(right, power(magic, i-n/2)); add(left, right); if(A == left) a++; } for(int i = 0; i<= n/2; i++) { int left = i?find_hash(0, i-1):0; int right = i+1<=n/2?find_hash(i+1, n/2):0; right = mul(right, power(magic, i)); add(left, right); if(left == B) b++; } if(a && b) nu(); if(!(a || b)) np(); if(a) for(int i = 0; i< n/2; i++) printf("%c", s[i]); else for(int i = n/2+1; i< n; i++) printf("%c", s[i]); return 0; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:76:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n; scanf("%d", &n);
                        ^
sequence.cpp:77:16: 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...