Submission #68057057
Source Code Expand
Copy
#include <stdio.h>#include <stdlib.h>#include <inttypes.h>int main(void) {int H, W;int** A;int* P;int64_t** required;int i, j;if (scanf("%d%d", &H, &W) != 2) return 1;A = malloc(sizeof(*A) * H);if (A == NULL) return 2;A[0] = malloc(sizeof(**A) * H * W);if (A[0] == NULL) return 2;for (i = 1; i < H; i++) {A[i] = A[0] + W * i;}for (i = 0; i < H; i++) {for (j = 0; j < W; j++) {if (scanf("%d", &A[i][j]) != 1) return 1;
#include <stdio.h> #include <stdlib.h> #include <inttypes.h> int main(void) { int H, W; int** A; int* P; int64_t** required; int i, j; if (scanf("%d%d", &H, &W) != 2) return 1; A = malloc(sizeof(*A) * H); if (A == NULL) return 2; A[0] = malloc(sizeof(**A) * H * W); if (A[0] == NULL) return 2; for (i = 1; i < H; i++) { A[i] = A[0] + W * i; } for (i = 0; i < H; i++) { for (j = 0; j < W; j++) { if (scanf("%d", &A[i][j]) != 1) return 1; } } P = malloc(sizeof(*P) * (H + W - 1)); if (P == NULL) return 2; required = malloc(sizeof(*required) * H); if (required == NULL) return 2; required[0] = malloc(sizeof(**required) * H * W); if (required[0] == NULL) return 2; for (i = 1; i < H; i++) { required[i] = required[0] + W * i; } for (i = 0; i < H + W - 1; i++) { if (scanf("%d", &P[i]) != 1) return 1; } for (i = H - 1; i >= 0; i--) { for (j = W - 1; j >= 0; j--) { int64_t cur_req = INT64_MAX; if (i == H - 1 && j == W - 1) cur_req = 0; if (i + 1 < H && required[i + 1][j] < cur_req) cur_req = required[i + 1][j]; if (j + 1 < W && required[i][j + 1] < cur_req) cur_req = required[i][j + 1]; cur_req += P[i + j]; cur_req -= A[i][j]; if (cur_req < 0) cur_req = 0; required[i][j] = cur_req; } } printf("%" PRId64 "\n", required[0][0]); free(required[0]); free(required); free(P); free(A[0]); free(A); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Hungry Takahashi |
User | mikecat |
Language | C (gcc 12.2.0) |
Score | 450 |
Code Size | 1442 Byte |
Status | AC |
Exec Time | 44 ms |
Memory | 7604 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 450 / 450 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 02_random2_00.txt, 02_random2_01.txt, 02_random2_02.txt, 02_random2_03.txt, 02_random2_04.txt, 02_random2_05.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt, 03_handmade_07.txt, 03_handmade_08.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_00.txt | AC | 0 ms | 1640 KiB |
00_sample_01.txt | AC | 0 ms | 1756 KiB |
00_sample_02.txt | AC | 0 ms | 1624 KiB |
01_random_00.txt | AC | 43 ms | 4628 KiB |
01_random_01.txt | AC | 38 ms | 4700 KiB |
01_random_02.txt | AC | 39 ms | 4584 KiB |
01_random_03.txt | AC | 35 ms | 4616 KiB |
01_random_04.txt | AC | 24 ms | 3816 KiB |
01_random_05.txt | AC | 24 ms | 3912 KiB |
01_random_06.txt | AC | 20 ms | 3908 KiB |
01_random_07.txt | AC | 20 ms | 3800 KiB |
01_random_08.txt | AC | 22 ms | 3792 KiB |
01_random_09.txt | AC | 22 ms | 3844 KiB |
01_random_10.txt | AC | 19 ms | 3828 KiB |
01_random_11.txt | AC | 19 ms | 3772 KiB |
01_random_12.txt | AC | 22 ms | 3828 KiB |
01_random_13.txt | AC | 22 ms | 3848 KiB |
01_random_14.txt | AC | 18 ms | 3836 KiB |
01_random_15.txt | AC | 19 ms | 3824 KiB |
01_random_16.txt | AC | 23 ms | 3700 KiB |
01_random_17.txt | AC | 23 ms | 3912 KiB |
01_random_18.txt | AC | 20 ms | 3812 KiB |
01_random_19.txt | AC | 19 ms | 3804 KiB |
01_random_20.txt | AC | 38 ms | 5684 KiB |
01_random_21.txt | AC | 31 ms | 5664 KiB |
01_random_22.txt | AC | 30 ms | 5676 KiB |
01_random_23.txt | AC | 28 ms | 5648 KiB |
01_random_24.txt | AC | 44 ms | 7536 KiB |
01_random_25.txt | AC | 40 ms | 7508 KiB |
01_random_26.txt | AC | 40 ms | 7504 KiB |
01_random_27.txt | AC | 36 ms | 7604 KiB |
02_random2_00.txt | AC | 12 ms | 3824 KiB |
02_random2_01.txt | AC | 14 ms | 3804 KiB |
02_random2_02.txt | AC | 16 ms | 3820 KiB |
02_random2_03.txt | AC | 16 ms | 3796 KiB |
02_random2_04.txt | AC | 18 ms | 3848 KiB |
02_random2_05.txt | AC | 19 ms | 3808 KiB |
03_handmade_00.txt | AC | 0 ms | 1724 KiB |
03_handmade_01.txt | AC | 0 ms | 1624 KiB |
03_handmade_02.txt | AC | 0 ms | 1712 KiB |
03_handmade_03.txt | AC | 10 ms | 3796 KiB |
03_handmade_04.txt | AC | 16 ms | 3788 KiB |
03_handmade_05.txt | AC | 16 ms | 3704 KiB |
03_handmade_06.txt | AC | 24 ms | 4620 KiB |
03_handmade_07.txt | AC | 25 ms | 4636 KiB |
03_handmade_08.txt | AC | 29 ms | 4608 KiB |