# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
491020 | kawaii | Fibonacci representations (CEOI18_fib) | C++14 | 14 ms | 8140 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define hash hashh
int t, hash[1000005], mod = 998244353, base = 353, mul[1000005];
string s;
void solve(){
mul[0] = 1;
for(int i = 1; i <= 1e6; i++) mul[i] = (mul[i - 1] * base) % mod;
while(t--){
cin >> s;
int ans = 0, n = s.size();
for(int i = 0; i < s.size(); i++) hash[i + 1] = (hash[i] * base + s[i]) % mod;
int l = 1, r = n, cnt = n;
while(l <= r){
int p = (hash[cnt] - hash[r - 1] * mul[cnt - r + 1]) % mod;
if(p < 0) p += mod;
int q = (hash[l + cnt - r] - hash[l - 1] * mul[cnt - r + 1]) % mod;
if(q < 0) q += mod;
if(p == q){
ans += 2;
if(l == r) ans--;
l += cnt - r + 1;
cnt = r - 1;
}
r--;
}
cout << ans << "\n";
}
}
signed main(){
ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
cin >> t;
solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |