제출 #918582

#제출 시각아이디문제언어결과실행 시간메모리
918582Boycl07회문 (APIO14_palindrome)C++17
0 / 100
21 ms39396 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 1; i <= n; ++i) #define forn(i, l, r) for(int i = l; i <= r; ++i) #define ford(i, r, l) for(int i = r; i >= l; --i) #define FOR(i, n) for(int i = 0; i < n; ++i) #define fi first #define se second #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define endl "\n" #define task "palindrome" #define sz(a) int(a.size()) #define C(x, y) make_pair(x, y) #define all(a) (a).begin(), (a).end() #define bit(i, mask) (mask >> i & 1) template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; } template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; } inline int readInt() {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();int n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;} inline ll readLong() {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();ll n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;} inline string readString() {char c;while(c=getchar(),c==' '||c=='\n'||c=='\t');string s({c});while(c=getchar(),c!=EOF&&c!=' '&&c!='\n'&&c!='\t')s+=c;return s;} const int N = 5e5 + 4; const int M = 3e5 + 3; const int K = 22; const int INF = 1e9 + 3; const ll LINF = 1e18; const int A = 26 + 2; int n; string s; int sz[N], suf[N], nx[N][A]; int cnt[N]; void solve() { cin >> s; n = sz(s); suf[0] = 0; sz[0] = -1; suf[1] = 0; sz[1] = 0; int cur_suf = 1; int num_node = 1; for(int i = 0; i < sz(s); ++i) { while(s[i] != s[i - sz[cur_suf] - 1]) cur_suf = suf[cur_suf]; if(!nx[cur_suf][s[i] - 'a']) { int p = suf[cur_suf]; while(s[p] != s[p - sz[p] - 1]) p = suf[p]; p = max(1, nx[p][s[i] -'a']); nx[cur_suf][s[i] - 'a'] = ++num_node; suf[num_node] = p; sz[num_node] = sz[cur_suf] + 2; } ++cnt[nx[cur_suf][s[i] - 'a']]; cur_suf = nx[cur_suf][s[i] - 'a']; } ll res = 0; ford(i, num_node, 1) { cnt[suf[i]] += cnt[i]; maximize(res, 1ll * sz[i] * cnt[i]); } cout << res; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int TC = 1; if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } while(TC--) { solve(); cout << endl; } return 0; }

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

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