(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.

제출 #1115117

#제출 시각아이디문제언어결과실행 시간메모리
1115117VinhLuu회문 (APIO14_palindrome)C++17
0 / 100
1073 ms90024 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 = 137ull; ull get(int l,int r){ return f[r] - 1ull * f[l] * lt[r - l + 1]; } ull rev(int l,int r){ return g[l] - 1ull * g[r + 1] * lt[r - l + 1]; } map<ull,int> mp; ll ans; void solve(){ lt[0] = 1; for(int i = 1; i <= n; i ++){ lt[i] = 1ull * lt[i - 1] * base; f[i] = 1ull * f[i - 1] * base + a[i]; } for(int i = n; i >= 1; i --) g[i] = 1ull * 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)] + 1; mp[get(pl, pr)]++; ans = max(ans, 1ll * val * (pr - pl + 1)); pl--; pr++; } pl = i, pr = i + 1; while(pl >= 1 && pr <= n){ if(a[pl] != a[pr]) break; int val = mp[get(pl, pr)] + 1; mp[get(pl, pr)]++; ans = max(ans, 1ll * val * (pr - pl + 1)); pl--; pr++; } } 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(); }

컴파일 시 표준 에러 (stderr) 메시지

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