제출 #1284349

#제출 시각아이디문제언어결과실행 시간메모리
1284349hiepsimauhongPalindromic Partitions (CEOI17_palindromic)C++20
60 / 100
10086 ms40556 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define FOR(I, L, R) for(int I(L) ; I <= (int)R ; ++I) #define FOD(I, R, L) for(int I(R) ; I >= (int)L ; --I) #define FOA(I, A) for(auto &I : A) #define print(A,L,R) FOR(OK, L, R){if(A[OK]<=-oo / 10||A[OK]>=oo)cout<<"- ";else cout<<A[OK]<<' ';}cout<<'\n'; #define prints(A) FOA(OK, A){cout<<OK<<' ';}cout << '\n'; #define printz(A,L,R) FOR(OK, 0, L){FOR(KO, 0, R){if(A[OK][KO]>-oo&&A[OK][KO]<oo)cout<<A[OK][KO]<<' ';else cout << "- ";} cout << '\n';}cout << '\n'; #define fs first #define sd second #define ii pair<int,int> #define iii pair<int, ii> #define all(A) A.begin(), A.end() #define quickly ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define pow lkhasf #define FILE kangaroo const int N = 1e6 + 5; const int mod[] = {(int)1e9 + 7, (int)1e9 + 9}; const int base = 27; const int oo = 1e18; int n; string s; int pow[2][N], dp[N]; struct Hashing{ int pre[2][N]; void build(string &t){ FOR(i, 1, t.size() - 1){ FOR(j, 0, 1){ pre[j][i] = (pre[j][i - 1] * base % mod[j] + t[i] - 'a' + 1) % mod[j]; } } } ii get(int l, int r){ int g0 = (pre[0][r] - pre[0][l - 1] * pow[0][r - l + 1] % mod[0] + mod[0]) % mod[0]; int g1 = (pre[1][r] - pre[1][l - 1] * pow[1][r - l + 1] % mod[1] + mod[1]) % mod[1]; return {g0, g1}; } } H; void solve(){ cin >> s; n = s.size(); s = " " + s; H.build(s); /// dp[i] la da chia toi i memset(dp, -0x3f, sizeof dp); dp[0] = 0; FOR(i, 0, n / 2){ FOR(j, i + 1, n / 2){ ii lf = H.get(i + 1, j); ii rg = H.get(n - j + 1, n - i); if(lf == rg){ dp[j] = max(dp[j], dp[i] + 1); } } } int ans = 0; FOR(i, 1, (n + 1) / 2 - 1){ ans = max(ans, dp[i] * 2); } ans++; ans = max(ans, dp[n / 2] * 2); cout << ans << '\n'; } signed main(){ quickly if(fopen("FILE.in", "r")){ freopen("FILE.in", "r", stdin); freopen("FILE.out", "w", stdout); } int test; cin >> test; pow[0][0] = pow[1][0] = 1; FOR(i, 1, 1e6){ FOR(j, 0, 1){ pow[j][i] = pow[j][i - 1] * base % mod[j]; } } while(test--){ solve(); } }

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

palindromic.cpp: In function 'int main()':
palindromic.cpp:86:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |                 freopen("FILE.in", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
palindromic.cpp:87:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |                 freopen("FILE.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...