Submission #549963

#TimeUsernameProblemLanguageResultExecution timeMemory
549963Duy_ePalindromes (APIO14_palindrome)C++14
0 / 100
2 ms340 KiB
/* ** TASK: ** LINK: */ #include <bits/stdc++.h> #define ll long long #define pii pair<ll, ll> #define st first #define nd second #define file "test" using namespace std; const long long INF = 1e18; const long long N = 2e5 + 5; const long long base = 311; const long long MOD = 1e9 + 321; string s; ll h[N], ph[N], pw[N], n; ll get(int l, int r) { return (h[r] - h[l - 1] * pw[r - l + 1] % MOD + MOD * MOD) % MOD; } ll getpre(int l, int r) { return (ph[l] - ph[r + 1] * pw[r - l + 1] % MOD + MOD * MOD) % MOD; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout); #endif cin >> s; s = '#' + s; n = s.size() - 1; pw[0] = 1; for (int i = 1; i <= n; i ++) { pw[i] = pw[i - 1] * base % MOD; h[i] = (h[i - 1] * base + s[i]) % MOD; } for (int i = n; i >= 1; i --) ph[i] = (ph[i + 1] * base + s[i]) % MOD; map <int, ll> dp; ll ans = 0; for (int i = 1; i <= n; i ++) for (int j = i; j <= n; j ++) { ll x = get(i, j); if (x == getpre(i, j)) { // cout << i << ' ' << j << '\n'; dp[x] += j - i + 1; ans = max(ans, dp[x]); } } cout << ans; return 0; } /** /\_/\ * (= ._.) * / >🍵 \>🍮 **/

Compilation message (stderr)

palindrome.cpp:67:9: warning: "/*" within comment [-Wcomment]
   67 | /**  /\_/\
      |          
palindrome.cpp: In function 'int main()':
palindrome.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
palindrome.cpp:33:49: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen(file".inp", "r", stdin); 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...
#Verdict Execution timeMemoryGrader output
Fetching results...