Submission #861958

#TimeUsernameProblemLanguageResultExecution timeMemory
861958anhphantPalindromic Partitions (CEOI17_palindromic)C++14
100 / 100
118 ms28756 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define endl '\n' const ll mod = 1e9 + 9; const ll base = 9973; string S; int N; ll basepow[1000007], pre[1000007]; ll getHash(int i, int j) { ll r = pre[j]; ll l = (pre[i - 1] * basepow[j - i + 1]) % mod; return (r - l + mod) % mod; } ll DP[1000007]; void solve() { cin >> S; int N = S.size(); S = " " + S; for(int i = 1; i <= N; ++i) { pre[i] = (pre[i - 1] * base + S[i] - 'a' + 1) % mod; } ll L = 1, R = N; ll ans = 0; while(L <= R) { //cerr << L << " " << R << endl; if (L == R) { ans++; break; } for(int i = L; i <= N / 2; ++i) { //cerr << "i = " << i << endl; if (getHash(L, i) == getHash(N - i + 1, R)) { ans += 2; L = i + 1; R = N - i; goto GT; } } //cerr << "end : " << L << " " << R << endl; ans += (L < R); break; GT:; if (L == R) { ans++; break; } } cout << ans << endl; } int main() { ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0); if (fopen("FILE.INP", "r")) { freopen("FILE.INP", "r", stdin); freopen("FILE.OUT", "w", stdout); } basepow[0] = 1; for(int i = 1; i <= 1000000; ++i) basepow[i] = (basepow[i - 1] * base) % mod; int Tc; cin >> Tc; for(int _ = 1; _ <= Tc; ++_) { //cerr << " _ = " << _ << endl; solve(); } }

Compilation message (stderr)

palindromic.cpp: In function 'int main()':
palindromic.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen("FILE.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
palindromic.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |         freopen("FILE.OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...