# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
468537 | 2021-08-28T16:42:51 Z | idk321 | Palindromic Partitions (CEOI17_palindromic) | C++17 | 10000 ms | 59232 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; string s; const int N = 1000001; const int MINF = -1000000000; const int MOD = 1000000007; const int P = 29; int res[N]; int vis[N]; ll power[N]; int calc(int n) { if (n == s.size() / 2) { if (s.size() % 2 == 1) return 1; return 0; } if (res[n]) return res[n]; ll hash1 = 0; ll hash2 = 0; int j = 0; int cres = 1; for (int i = n; i < s.size() / 2; i++, j++) { hash2 *= P; hash2 %= MOD; hash1 += (s[i] - 'a') * power[j]; hash1 %= MOD; hash2 += s[s.size() - 1 - i] - 'a'; hash2 %= MOD; //cout << i << " " << hash1 << " " << hash2 << " " << s.size()<< endl; if (hash1 == hash2) { cres = max(cres, 2 + calc(i + 1)); } } res[n] = cres; return res[n]; } int main() { ios::sync_with_stdio(0); cin.tie(0); power[0] = 1; for (int i = 1; i <N; i++) { power[i] = power[i - 1] * P; power[i] %= MOD; } int t; cin >> t; for (int t1 = 0; t1 < t; t1++) { cin >> s; int cres = 0; for (int i = 0; i < s.size() / 2 + 1; i++) res[i] = 0; cout << calc(0) << "\n"; } } /* 4 bonobo deleted racecar racecars */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 8140 KB | Output is correct |
2 | Correct | 10 ms | 8140 KB | Output is correct |
3 | Correct | 10 ms | 8108 KB | Output is correct |
4 | Correct | 9 ms | 8148 KB | Output is correct |
5 | Correct | 10 ms | 8144 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 8140 KB | Output is correct |
2 | Correct | 10 ms | 8140 KB | Output is correct |
3 | Correct | 10 ms | 8108 KB | Output is correct |
4 | Correct | 9 ms | 8148 KB | Output is correct |
5 | Correct | 10 ms | 8144 KB | Output is correct |
6 | Correct | 11 ms | 8060 KB | Output is correct |
7 | Correct | 10 ms | 8148 KB | Output is correct |
8 | Correct | 10 ms | 8140 KB | Output is correct |
9 | Correct | 11 ms | 8140 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 8140 KB | Output is correct |
2 | Correct | 10 ms | 8140 KB | Output is correct |
3 | Correct | 10 ms | 8108 KB | Output is correct |
4 | Correct | 9 ms | 8148 KB | Output is correct |
5 | Correct | 10 ms | 8144 KB | Output is correct |
6 | Correct | 11 ms | 8060 KB | Output is correct |
7 | Correct | 10 ms | 8148 KB | Output is correct |
8 | Correct | 10 ms | 8140 KB | Output is correct |
9 | Correct | 11 ms | 8140 KB | Output is correct |
10 | Correct | 538 ms | 8736 KB | Output is correct |
11 | Correct | 103 ms | 8396 KB | Output is correct |
12 | Correct | 24 ms | 8180 KB | Output is correct |
13 | Correct | 463 ms | 8440 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 8140 KB | Output is correct |
2 | Correct | 10 ms | 8140 KB | Output is correct |
3 | Correct | 10 ms | 8108 KB | Output is correct |
4 | Correct | 9 ms | 8148 KB | Output is correct |
5 | Correct | 10 ms | 8144 KB | Output is correct |
6 | Correct | 11 ms | 8060 KB | Output is correct |
7 | Correct | 10 ms | 8148 KB | Output is correct |
8 | Correct | 10 ms | 8140 KB | Output is correct |
9 | Correct | 11 ms | 8140 KB | Output is correct |
10 | Correct | 538 ms | 8736 KB | Output is correct |
11 | Correct | 103 ms | 8396 KB | Output is correct |
12 | Correct | 24 ms | 8180 KB | Output is correct |
13 | Correct | 463 ms | 8440 KB | Output is correct |
14 | Execution timed out | 10042 ms | 59232 KB | Time limit exceeded |
15 | Halted | 0 ms | 0 KB | - |