Submission #2302462
Source Code Expand
#include <iostream> #include <string> #include <algorithm> using namespace std; long long n, dp[5009], L[5009], L1[5009][5009], L2[5009][5009], mod = 1145141919810; bool I[5009][5009]; string S; bool ispal(int l, int r) { int m = (l + r + 1) / 2; long long V1 = L1[l][m - 1]; long long V2 = L2[m][r]; if ((r - l) % 2 == 0) V2 = L2[m + 1][r]; if (V1 == V2) return true; return false; } int main() { cin >> n >> S; for (int i = 0; i < S.size(); i++) { long long Z = 0; for (int j = i; j < S.size(); j++) { Z *= 29LL; Z += (S[j] - 'a' + 1); Z %= mod; L1[i][j] = Z; } long long ZZ = 0; for (int j = i; j >= 0; j--) { ZZ *= 29LL; ZZ += (S[j] - 'a' + 1); ZZ %= mod; L2[j][i] = ZZ; } } for (int i = 1; i <= n; i++) cin >> L[i]; for (int i = 1; i <= n; i++) dp[i] = (1LL << 60); for (int i = 1; i <= S.size(); i++) { for (int j = 0; j < i; j++) { if (ispal(j, i - 1) == false) continue; dp[i] = min(dp[i], dp[j] + L[i - j]); } } cout << dp[n] << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Palindrome Concatenation |
User | E869120 |
Language | C++14 (GCC 5.4.1) |
Score | 40 |
Code Size | 1056 Byte |
Status | MLE |
Exec Time | 570 ms |
Memory | 393728 KB |
Judge Result
Set Name | Sample | Dataset1 | Dataset2 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 40 / 40 | 0 / 60 | ||||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | sample-01.txt, sample-02.txt, sample-03.txt |
Dataset1 | sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt |
Dataset2 | 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt, 02-17.txt, 02-18.txt, 02-19.txt, 02-20.txt, 02-21.txt, 02-22.txt, 02-23.txt, 02-24.txt, sample-01.txt, sample-02.txt, sample-03.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 2 ms | 4352 KB |
01-02.txt | AC | 2 ms | 4352 KB |
01-03.txt | AC | 4 ms | 12544 KB |
01-04.txt | AC | 6 ms | 20736 KB |
01-05.txt | AC | 6 ms | 20736 KB |
01-06.txt | AC | 6 ms | 20736 KB |
01-07.txt | AC | 6 ms | 20736 KB |
01-08.txt | AC | 6 ms | 20736 KB |
01-09.txt | AC | 6 ms | 20736 KB |
01-10.txt | AC | 6 ms | 20736 KB |
01-11.txt | AC | 6 ms | 20736 KB |
01-12.txt | AC | 6 ms | 20736 KB |
01-13.txt | AC | 6 ms | 20736 KB |
01-14.txt | AC | 6 ms | 20736 KB |
01-15.txt | AC | 6 ms | 20736 KB |
01-16.txt | AC | 6 ms | 20736 KB |
01-17.txt | AC | 6 ms | 20736 KB |
01-18.txt | AC | 6 ms | 20736 KB |
01-19.txt | AC | 6 ms | 20736 KB |
01-20.txt | AC | 6 ms | 20736 KB |
01-21.txt | AC | 6 ms | 20736 KB |
02-01.txt | AC | 36 ms | 84224 KB |
02-02.txt | AC | 108 ms | 162048 KB |
02-03.txt | AC | 201 ms | 229632 KB |
02-04.txt | MLE | 548 ms | 393600 KB |
02-05.txt | MLE | 570 ms | 393600 KB |
02-06.txt | MLE | 553 ms | 393600 KB |
02-07.txt | MLE | 548 ms | 393600 KB |
02-08.txt | MLE | 570 ms | 393600 KB |
02-09.txt | MLE | 548 ms | 393600 KB |
02-10.txt | MLE | 547 ms | 393600 KB |
02-11.txt | MLE | 548 ms | 393728 KB |
02-12.txt | MLE | 548 ms | 393600 KB |
02-13.txt | MLE | 548 ms | 393600 KB |
02-14.txt | MLE | 547 ms | 393600 KB |
02-15.txt | MLE | 548 ms | 393600 KB |
02-16.txt | MLE | 547 ms | 393600 KB |
02-17.txt | MLE | 548 ms | 393600 KB |
02-18.txt | MLE | 548 ms | 393600 KB |
02-19.txt | MLE | 548 ms | 393600 KB |
02-20.txt | MLE | 548 ms | 393600 KB |
02-21.txt | MLE | 548 ms | 393600 KB |
02-22.txt | MLE | 548 ms | 393600 KB |
02-23.txt | MLE | 561 ms | 393600 KB |
02-24.txt | MLE | 561 ms | 393600 KB |
sample-01.txt | AC | 2 ms | 6400 KB |
sample-02.txt | AC | 2 ms | 6400 KB |
sample-03.txt | AC | 2 ms | 6400 KB |