Submission #1350600
Source Code Expand
#include <stdio.h> #include <stdlib.h> #define inf (int)(1e9) int max(int a, int b){ if(a > b){ return a; } else{ return b; } } int min(int a, int b){ if(a < b){ return a; } else{ return b; } } int main(){ int N, i, j, k, lmax = 0, dpmin; scanf("%d", &N); int *l = (int *)malloc(sizeof(int) * N); int *r = (int *)malloc(sizeof(int) * N); for(i = 0; i < N; i++){ scanf("%d%d", &l[i], &r[i]); lmax = max(l[i], lmax); l[i]--; r[i]--; } int **dp = (int **)malloc(sizeof(int *) * N); for(i = 0; i < N; i++){ dp[i] = (int *)malloc(sizeof(int) * lmax); } for(j = 0; j < lmax; j++){ dp[0][j] = abs(j - l[0]); } for(i = 1; i < N; i++){ for(j = 0; j < lmax; j++){ dpmin = inf; for(k = max(0, j - (r[i - 1] - l[i - 1])); k < min(lmax, j + r[i] - l[i] + 1); k++){ dpmin = min(dp[i - 1][k], dpmin); } dp[i][j] = dpmin + abs(j - l[i]); } } dpmin = inf; for(j = 0; j < lmax; j++){ dpmin = min(dp[N - 1][j], dpmin); } /*printf("lmax = %d\n", lmax); for(i = 0; i < N; i++){ printf("i = %d: ", i); for(j = 0; j < lmax; j++){ printf("%d ", dp[i][j]); } printf("\n"); }*/ printf("%d\n", dpmin); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - NarrowRectangles |
User | abc050 |
Language | C (GCC 5.4.1) |
Score | 300 |
Code Size | 1236 Byte |
Status | RE |
Exec Time | 3375 ms |
Memory | 4864 KB |
Compile Error
./Main.c: In function ‘main’: ./Main.c:26:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &N); ^ ./Main.c:30:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d", &l[i], &r[i]); ^
Judge Result
Set Name | Sample | Subtask | All | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | 0 / 700 | ||||||||||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt |
Subtask | 0_000, 0_001, 0_004, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 2_018.txt, 2_019.txt, 2_020.txt, 2_021.txt, 2_022.txt, 2_023.txt, 2_024.txt, 2_025.txt, 2_026.txt, 2_027.txt, 2_028.txt, 2_029.txt, 2_030.txt, 2_031.txt, 2_032.txt, 2_033.txt, 2_034.txt, 2_035.txt, 2_036.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 1 ms | 128 KB |
0_001.txt | AC | 1 ms | 128 KB |
0_002.txt | RE | 98 ms | 128 KB |
0_003.txt | TLE | 2103 ms | 896 KB |
0_004.txt | AC | 1 ms | 128 KB |
1_005.txt | AC | 2 ms | 768 KB |
1_006.txt | AC | 2 ms | 768 KB |
1_007.txt | AC | 1 ms | 128 KB |
1_008.txt | AC | 25 ms | 768 KB |
1_009.txt | AC | 23 ms | 768 KB |
1_010.txt | AC | 25 ms | 768 KB |
1_011.txt | AC | 25 ms | 768 KB |
1_012.txt | AC | 24 ms | 768 KB |
1_013.txt | AC | 26 ms | 768 KB |
1_014.txt | AC | 26 ms | 768 KB |
1_015.txt | AC | 25 ms | 768 KB |
1_016.txt | AC | 26 ms | 768 KB |
1_017.txt | AC | 27 ms | 768 KB |
2_018.txt | RE | 287 ms | 1664 KB |
2_019.txt | RE | 289 ms | 1664 KB |
2_020.txt | AC | 23 ms | 4864 KB |
2_021.txt | RE | 291 ms | 1664 KB |
2_022.txt | RE | 289 ms | 1664 KB |
2_023.txt | RE | 289 ms | 1664 KB |
2_024.txt | RE | 287 ms | 1664 KB |
2_025.txt | RE | 286 ms | 1664 KB |
2_026.txt | RE | 288 ms | 1664 KB |
2_027.txt | RE | 286 ms | 1664 KB |
2_028.txt | RE | 287 ms | 1664 KB |
2_029.txt | RE | 285 ms | 1664 KB |
2_030.txt | RE | 286 ms | 1664 KB |
2_031.txt | RE | 287 ms | 1664 KB |
2_032.txt | RE | 286 ms | 1664 KB |
2_033.txt | RE | 285 ms | 1664 KB |
2_034.txt | RE | 287 ms | 1664 KB |
2_035.txt | TLE | 2452 ms | -1455232 KB |
2_036.txt | TLE | 3375 ms | -1357064 KB |