제출 #676328

#제출 시각아이디문제언어결과실행 시간메모리
676328vuavisao회문 (APIO14_palindrome)C++14
23 / 100
1082 ms988 KiB
#include<bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define ll long long using namespace std; template<typename Lhs, typename Rhs> inline bool Max_self(Lhs &a, Rhs b) { if(b > a) { a = b; return true; } return false; } template<typename Lhs, typename Rhs> inline bool Min_self(Lhs &a, Rhs b) { if(b < a) { a = b; return true; } return false; } const int N = 3e5 + 10; int n; string s; namespace sub123 { bool check() { return n <= 10000; } const int BASE = 128; const int MOD = 1e9 + 7; int p[N], h[N], h_rev[N]; int res; int get_hash(int l, int r, int* h) { return (h[r] - 1ll * h[l - 1] * p[r - l + 1] % MOD + MOD) % MOD; } void solve() { p[0] = 1; for(int i = 1; i <= n; ++ i) { p[i] = 1ll * p[i - 1] * BASE % MOD; h[i] = (1ll * h[i - 1] * BASE + s[i]) % MOD; h_rev[i] = (1ll * h_rev[i - 1] * BASE + s[n - i + 1]) % MOD; } for(int len = 1; len <= n; ++ len) { unordered_map<int, int> mpp; auto palin = [&] (int l, int r) -> bool { return get_hash(l, r, h) == get_hash(n - r + 1, n - l + 1, h_rev); }; for(int i = 1; i <= n - len + 1; ++ i) { if(palin(i, i + len - 1)) { int hash = get_hash(i, i + len - 1, h); ++ mpp[hash]; Max_self(res, mpp[hash] * len); } } } cout << res; } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("APIO14_palindrome.inp", "r")) { freopen("APIO14_palindrome.inp", "r", stdin); freopen("APIO14_palindrome.out", "w", stdout); } cin >> s; n = (int) s.size(); s = ' ' + s; if(sub123::check()) { sub123::solve(); return 0; } return 0; } /// Code by vuavisao

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

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