Submission #2302453
Source Code Expand
#include <iostream> #include <algorithm> #include <vector> using namespace std; int N; vector<vector<bool>> if_palindrome; // [left, right] vector<int> costs; int dp[5000]; int split(int now){ if(now == N){ return 0; }else if(dp[now] != -1){ return dp[now]; }else{ int ans = 1e9; for(int i = 1; now + i <= N; i++){ if(if_palindrome[now][now + i - 1]){ ans = min(ans, costs[i - 1] + split(now + i)); } } return dp[now] = ans; } } int main(){ string S; cin >> N >> S; costs.resize(N); for(int i = 0; i < N; i++){ cin >> costs[i]; } if_palindrome.resize(N); for(int i = 0; i < N; i++){ if_palindrome[i].resize(N); for(int j = 0; j < N; j++){ if_palindrome[i][j] = false; } } for(int i = 0; i < N; i++){ for(int j = 0; i - j >= 0 && i + j < N; j++){ if(S[i - j] != S[i + j]){ break; } if_palindrome[i - j][i + j] = true; } } for(int i = 0; i < N - 1; i++){ for(int j = 0; i - j >= 0 && i + j + 1 < N; j++){ if(S[i - j] != S[i + j + 1]){ break; } if_palindrome[i - j][i + j + 1] = true; } } fill(dp, dp + 5000, -1); cout << split(0) << endl; }
Submission Info
Submission Time | |
---|---|
Task | C - Palindrome Concatenation |
User | June_boy |
Language | Text (cat) |
Score | 0 |
Code Size | 1443 Byte |
Status | WA |
Exec Time | 2 ms |
Memory | 256 KB |
Judge Result
Set Name | Sample | Dataset1 | Dataset2 | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | WA | 1 ms | 128 KB |
01-02.txt | WA | 1 ms | 128 KB |
01-03.txt | WA | 1 ms | 128 KB |
01-04.txt | WA | 1 ms | 128 KB |
01-05.txt | WA | 1 ms | 128 KB |
01-06.txt | WA | 1 ms | 128 KB |
01-07.txt | WA | 1 ms | 128 KB |
01-08.txt | WA | 1 ms | 128 KB |
01-09.txt | WA | 1 ms | 128 KB |
01-10.txt | WA | 1 ms | 128 KB |
01-11.txt | WA | 1 ms | 128 KB |
01-12.txt | WA | 1 ms | 128 KB |
01-13.txt | WA | 1 ms | 128 KB |
01-14.txt | WA | 1 ms | 128 KB |
01-15.txt | WA | 1 ms | 128 KB |
01-16.txt | WA | 1 ms | 128 KB |
01-17.txt | WA | 1 ms | 128 KB |
01-18.txt | WA | 1 ms | 128 KB |
01-19.txt | WA | 1 ms | 128 KB |
01-20.txt | WA | 1 ms | 128 KB |
01-21.txt | WA | 1 ms | 128 KB |
02-01.txt | WA | 1 ms | 128 KB |
02-02.txt | WA | 1 ms | 128 KB |
02-03.txt | WA | 1 ms | 128 KB |
02-04.txt | WA | 1 ms | 128 KB |
02-05.txt | WA | 1 ms | 128 KB |
02-06.txt | WA | 1 ms | 128 KB |
02-07.txt | WA | 1 ms | 128 KB |
02-08.txt | WA | 1 ms | 128 KB |
02-09.txt | WA | 1 ms | 128 KB |
02-10.txt | WA | 1 ms | 128 KB |
02-11.txt | WA | 1 ms | 128 KB |
02-12.txt | WA | 1 ms | 128 KB |
02-13.txt | WA | 1 ms | 128 KB |
02-14.txt | WA | 1 ms | 128 KB |
02-15.txt | WA | 1 ms | 128 KB |
02-16.txt | WA | 1 ms | 128 KB |
02-17.txt | WA | 1 ms | 128 KB |
02-18.txt | WA | 1 ms | 128 KB |
02-19.txt | WA | 2 ms | 256 KB |
02-20.txt | WA | 1 ms | 128 KB |
02-21.txt | WA | 1 ms | 128 KB |
02-22.txt | WA | 1 ms | 128 KB |
02-23.txt | WA | 1 ms | 128 KB |
02-24.txt | WA | 1 ms | 128 KB |
sample-01.txt | WA | 1 ms | 128 KB |
sample-02.txt | WA | 1 ms | 128 KB |
sample-03.txt | WA | 1 ms | 128 KB |