Submission #1095040

#TimeUsernameProblemLanguageResultExecution timeMemory
1095040vjudge1Palindromic Partitions (CEOI17_palindromic)C++17
100 / 100
194 ms20568 KiB
#include<bits/stdc++.h> #define ll long long #define ii pair < int , int > #define iii pair < int , ii> #define iv pair < ii , ii > #define fi first #define se second #define y1 dkjfd using namespace std; const int N = 1e6 + 5; const int mod = 1e9 + 7; const int base = 310; int pre[N], pw[N]; int mul(int x, int y) { return 1LL * x * y % mod; } int add(int x, int y) { return ((1LL * x + y) % mod + mod) % mod; } int get(int l, int r) { return add(pre[r], - mul(pre[l - 1], pw[r - l + 1])); } main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("wormsort.in" , "r" , stdin); // freopen("wormsort.out" , "w" , stdout); pw[0] = 1; for(int i = 1; i <= 1e6; i++) pw[i] = mul(pw[i - 1], base); int t; cin >> t; while(t--) { string s; cin >> s; int n = s.size(); s = '#' + s; for(int i = 1; i <= n; i++) pre[i] = add(mul(pre[i - 1], base), s[i]); int ans = 0; int i = 1; int d = 1; while(true) { while(get(i, i + d - 1) != get(n - i - d + 2, n - i + 1)) d++; // cout << i << " " << d << endl; if(i != n - i - d + 2) ans += 2; else ans += 1; i += d; d = 1; if(i > (n + 1) / 2) break; } cout << ans << '\n'; } }

Compilation message (stderr)

palindromic.cpp:30:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   30 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...