Submission #3374674
Source Code Expand
#include<stdio.h> #include<stdlib.h> #define MIN(a,b) ((a)<(b)?(a):(b)) #define POS(i,j) ((i)*(n+1)+(j)) void run(void){ int n; scanf("%d",&n); char *s=(char *)malloc(sizeof(char)*(n+1)); scanf("%s",s); int *isPalindrome=(int *)calloc((n+1)*(n+1),sizeof(int)); int i,j; for(i=0;i<n;i++){ isPalindrome[POS(i,i)]=1; for(j=1;i+j<n && i-j>=0;j++){ if(s[i+j]!=s[i-j]) break; isPalindrome[POS(i-j,i+j)]=1; } for(j=0;i-j>=0 && i+1+j<n;j++){ if(s[i-j]!=s[i+1+j]) break; isPalindrome[POS(i-j,i+1+j)]=1; } } int *c=(int *)malloc(sizeof(int)*(n+1)); for(i=1;i<=n;i++) scanf("%d",c+i); int *dp=(int *)malloc(sizeof(int)*(n+1)); dp[n]=0; for(i=n-1;i>=0;i--){ int local=c[1]+dp[i+1]; for(j=2;j+i<=n;j++){ if(isPalindrome[POS(i,i+j-1)]) local=MIN(local,c[j]+dp[i+j]); } dp[i]=local; } printf("%d\n",dp[0]); } int main(void){ run(); return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Palindrome Concatenation |
User | sansen |
Language | C (GCC 5.4.1) |
Score | 100 |
Code Size | 976 Byte |
Status | AC |
Exec Time | 65 ms |
Memory | 97920 KB |
Compile Error
./Main.c: In function ‘run’: ./Main.c:10:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&n); ^ ./Main.c:12:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s",s); ^ ./Main.c:27:21: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] for(i=1;i<=n;i++) scanf("%d",c+i); ^
Judge Result
Set Name | Sample | Dataset1 | Dataset2 | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 40 / 40 | 60 / 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 | 1 ms | 128 KB |
01-02.txt | AC | 1 ms | 128 KB |
01-03.txt | AC | 1 ms | 256 KB |
01-04.txt | AC | 1 ms | 256 KB |
01-05.txt | AC | 1 ms | 384 KB |
01-06.txt | AC | 1 ms | 384 KB |
01-07.txt | AC | 1 ms | 384 KB |
01-08.txt | AC | 1 ms | 384 KB |
01-09.txt | AC | 1 ms | 384 KB |
01-10.txt | AC | 1 ms | 384 KB |
01-11.txt | AC | 1 ms | 384 KB |
01-12.txt | AC | 1 ms | 384 KB |
01-13.txt | AC | 1 ms | 384 KB |
01-14.txt | AC | 1 ms | 384 KB |
01-15.txt | AC | 1 ms | 256 KB |
01-16.txt | AC | 1 ms | 384 KB |
01-17.txt | AC | 1 ms | 384 KB |
01-18.txt | AC | 1 ms | 384 KB |
01-19.txt | AC | 1 ms | 384 KB |
01-20.txt | AC | 1 ms | 384 KB |
01-21.txt | AC | 1 ms | 384 KB |
02-01.txt | AC | 3 ms | 4096 KB |
02-02.txt | AC | 5 ms | 15232 KB |
02-03.txt | AC | 10 ms | 31488 KB |
02-04.txt | AC | 28 ms | 95104 KB |
02-05.txt | AC | 65 ms | 97920 KB |
02-06.txt | AC | 29 ms | 96768 KB |
02-07.txt | AC | 28 ms | 95104 KB |
02-08.txt | AC | 65 ms | 96640 KB |
02-09.txt | AC | 29 ms | 96768 KB |
02-10.txt | AC | 29 ms | 95104 KB |
02-11.txt | AC | 28 ms | 95104 KB |
02-12.txt | AC | 29 ms | 96768 KB |
02-13.txt | AC | 28 ms | 95104 KB |
02-14.txt | AC | 28 ms | 95104 KB |
02-15.txt | AC | 29 ms | 96768 KB |
02-16.txt | AC | 29 ms | 95104 KB |
02-17.txt | AC | 29 ms | 95104 KB |
02-18.txt | AC | 29 ms | 96768 KB |
02-19.txt | AC | 29 ms | 96768 KB |
02-20.txt | AC | 29 ms | 96768 KB |
02-21.txt | AC | 28 ms | 96768 KB |
02-22.txt | AC | 29 ms | 96768 KB |
02-23.txt | AC | 49 ms | 96640 KB |
02-24.txt | AC | 49 ms | 96512 KB |
sample-01.txt | AC | 1 ms | 128 KB |
sample-02.txt | AC | 1 ms | 128 KB |
sample-03.txt | AC | 1 ms | 128 KB |