(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #1115115

#TimeUsernameProblemLanguageResultExecution timeMemory
1115115VinhLuuPalindromes (APIO14_palindrome)C++17
0 / 100
1063 ms4596 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 2e5 + 5; int n, a[N]; namespace sub1{ ll ans; void solve(){ for(int i = 1; i <= n; i ++){ stack<int> st; for(int j = i; j <= n; j ++){ bool gg = true; int mid = (i + j) / 2; if((j - i + 1) & 1){ int pl = mid - 1, pr = mid + 1; while(pl >= i && pr <= j){ if(a[pl] != a[pr]){ gg = false; break; } pl--; pr++; } }else{ int pl = mid, pr = mid + 1; while(pl >= i && pr <= j){ if(a[pl] != a[pr]){ gg = false; break; } pl--; pr++; } } if(gg){ int cnt = 0; for(int k = 1; k <= n - (j - i + 1) + 1; k ++){ bool ff = true; for(int h = k; h <= k + (j - i + 1) - 1; h ++){ if(a[h] != a[i + h - k]){ ff = false; break; } } if(ff) cnt++; } ans = max(ans, 1ll * cnt * (j - i + 1)); } } } cout << ans; } } namespace sub2{ #define ull unsigned long long ull lt[N], f[N], g[N], base = 137; ull get(int l,int r){ return f[r] - f[l] * lt[r - l + 1]; } ull rev(int l,int r){ return g[l] - g[r + 1] * lt[r - l + 1]; } unordered_map<ull,int> mp; ll ans; void solve(){ lt[0] = 1; for(int i = 1; i <= n; i ++){ lt[i] = lt[i - 1] * base; f[i] = f[i - 1] * base + a[i]; } for(int i = n; i >= 1; i --) g[i] = g[i + 1] * base + a[i]; for(int i = 1; i <= n; i ++){ int pl = i, pr = i; while(pl >= 1 && pr <= n){ if(a[pl] != a[pr]) break; int val = ++mp[get(pl, pr)]; ans = max(ans, 1ll * val * (pr - pl + 1)); } pl = i, pr = i + 1; while(pl >= 1 && pr <= n){ if(a[pl] != a[pr]) break; int val = ++mp[get(pl, pr)]; ans = max(ans, 1ll * val * (pr - pl + 1)); } } cout << ans; } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "palindrome" if(fopen(task ".inp","r")){ freopen(task ".inp","r",stdin); freopen(task ".out","w",stdout); } string s; cin >> s; n = s.size(); s = " " + s; for(int i = 1; i <= n; i ++) a[i] = (int)(s[i] - 'a' + 1); sub2 :: solve(); }

Compilation message (stderr)

palindrome.cpp: In function 'int main()':
palindrome.cpp:104:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |     freopen(task ".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
palindrome.cpp:105:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  105 |     freopen(task ".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...