제출 #95921

#제출 시각아이디문제언어결과실행 시간메모리
95921KastandaPalindromic Partitions (CEOI17_palindromic)C++11
100 / 100
923 ms129692 KiB
#include<bits/stdc++.h> using namespace std; const int MXN = 1000006, SGM = 26; int n, ts, link[MXN], len[MXN]; int slink[MXN], diff[MXN], sdp[MXN], dp[MXN]; map < int , int > C[MXN]; char S[MXN], _S[MXN]; inline int GetLink(int nw, int i) { while (S[i] != S[i - len[nw] - 1]) nw = link[nw]; return (nw); } inline int Add(int nw, int i) { int ch = S[i] - 'a'; nw = GetLink(nw, i); if (!C[nw][ch]) { ts ++; len[ts] = len[nw] + 2; link[ts] = C[GetLink(link[nw], i)][ch]; diff[ts] = len[ts] - len[link[ts]]; slink[ts] = link[ts]; if (diff[ts] == diff[link[ts]]) slink[ts] = slink[link[ts]]; C[nw][ch] = ts; return (ts); } return (C[nw][ch]); } int main() { int q; scanf("%d", &q); for (; q; q --) { memset(_S, 0, sizeof(_S)); scanf("%s", _S); n = strlen(_S); for (int i = 1; i < n; i += 2) { S[i - 1] = _S[i >> 1]; S[i] = _S[n - 1 - (i >> 1)]; } link[0] = link[1] = 1; len[1] = -1; ts = 1; sdp[0] = sdp[1] = - MXN; dp[0] = 0; int nw = 1, Mx = 1; for (int i = 1; i <= (n >> 1 << 1); i++) { dp[i] = - MXN; nw = Add(nw, i - 1); for (int u = nw; len[u] > 0; u = slink[u]) { sdp[u] = dp[i - len[slink[u]] - diff[u]]; if (diff[u] == diff[link[u]]) sdp[u] = max(sdp[u], sdp[link[u]]); if (!(i & 1)) dp[i] = max(dp[i], sdp[u] + 1); } Mx = max(Mx, dp[i] + dp[i] + (i < n)); } for (int i = 0; i <= ts; i++) C[i].clear(); printf("%d\n", Mx); } return 0; }

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

palindromic.cpp: In function 'int main()':
palindromic.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &q);
     ~~~~~^~~~~~~~~~
palindromic.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s", _S);
         ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...