Submission #1178994
Source Code Expand
#include <stdio.h> #include <stdlib.h> int comp(const void *p1, const void *p2) { return *(const int *)p1 - *(const int*)p2; } int needs(int); int N, K, a[5010]; int dp[5010][5010]; int main(void) { int i, left, right, center; scanf("%d%d", &N, &K); for (i = 0; i < N; i++) { scanf("%d", &a[i]); // 解に関係ない値は読み飛ばす if (a[i] >= K) { N--; i--; } } qsort(a, N, sizeof(int), comp); // 二分探索で解を探す left = 0; right = N - 1; while (left <= right) { center = (left + right) / 2; if (needs(center)) right = center - 1; else left = center + 1; } printf("%d\n", left); return 0; } int needs(int index) { int i, j; // 最初と飛ばすの行のみ初期化 for (j = 0; j < K; j++) { dp[0][j] = 0; dp[index][j] = 0; } if (index != 0) dp[0][a[0]] = 1; dp[0][0] = 1; for (i = 1; i < N; i++) { for (j = 0; j < K; j++) { dp[i][j] = dp[i - 1][j]; if (i != index && j - a[i] >= 0) dp[i][j] |= dp[i - 1][j - a[i]]; } } for (j = K - a[index]; j < K; j++) { if (dp[N - 1][j] == 1) return 1; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - No Need |
User | shiita0903 |
Language | C (GCC 5.4.1) |
Score | 600 |
Code Size | 1172 Byte |
Status | AC |
Exec Time | 549 ms |
Memory | 98044 KB |
Compile Error
./Main.c: In function ‘main’: ./Main.c:15:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d", &N, &K); ^ ./Main.c:17:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &a[i]); ^
Judge Result
Set Name | Sample | Subtask | All | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | 300 / 300 | ||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt |
Subtask | 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_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, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_025.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_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, 1_018.txt, 1_019.txt, 1_020.txt, 1_021.txt, 1_022.txt, 1_023.txt, 1_024.txt, 1_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, 2_037.txt, 2_038.txt, 2_039.txt, 2_040.txt, 2_041.txt, 2_042.txt, 2_043.txt, 2_044.txt, 2_045.txt, 2_046.txt, 2_047.txt, 2_048.txt, 2_049.txt, 2_050.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 1 ms | 128 KB |
0_001.txt | AC | 1 ms | 256 KB |
0_002.txt | AC | 1 ms | 128 KB |
1_003.txt | AC | 0 ms | 128 KB |
1_004.txt | AC | 1 ms | 128 KB |
1_005.txt | AC | 1 ms | 128 KB |
1_006.txt | AC | 1 ms | 256 KB |
1_007.txt | AC | 1 ms | 256 KB |
1_008.txt | AC | 4 ms | 6908 KB |
1_009.txt | AC | 5 ms | 6908 KB |
1_010.txt | AC | 1 ms | 128 KB |
1_011.txt | AC | 1 ms | 128 KB |
1_012.txt | AC | 1 ms | 128 KB |
1_013.txt | AC | 1 ms | 128 KB |
1_014.txt | AC | 1 ms | 128 KB |
1_015.txt | AC | 4 ms | 6908 KB |
1_016.txt | AC | 1 ms | 256 KB |
1_017.txt | AC | 1 ms | 256 KB |
1_018.txt | AC | 1 ms | 256 KB |
1_019.txt | AC | 1 ms | 256 KB |
1_020.txt | AC | 2 ms | 6780 KB |
1_021.txt | AC | 3 ms | 6780 KB |
1_022.txt | AC | 1 ms | 2688 KB |
1_023.txt | AC | 1 ms | 512 KB |
1_024.txt | AC | 2 ms | 4736 KB |
1_025.txt | AC | 2 ms | 2688 KB |
2_026.txt | AC | 0 ms | 128 KB |
2_027.txt | AC | 1 ms | 256 KB |
2_028.txt | AC | 1 ms | 256 KB |
2_029.txt | AC | 509 ms | 98044 KB |
2_030.txt | AC | 549 ms | 98044 KB |
2_031.txt | AC | 1 ms | 128 KB |
2_032.txt | AC | 1 ms | 128 KB |
2_033.txt | AC | 1 ms | 128 KB |
2_034.txt | AC | 1 ms | 128 KB |
2_035.txt | AC | 1 ms | 128 KB |
2_036.txt | AC | 413 ms | 98044 KB |
2_037.txt | AC | 1 ms | 384 KB |
2_038.txt | AC | 1 ms | 384 KB |
2_039.txt | AC | 1 ms | 384 KB |
2_040.txt | AC | 1 ms | 384 KB |
2_041.txt | AC | 226 ms | 97020 KB |
2_042.txt | AC | 335 ms | 98044 KB |
2_043.txt | AC | 126 ms | 41084 KB |
2_044.txt | AC | 156 ms | 57212 KB |
2_045.txt | AC | 84 ms | 54524 KB |
2_046.txt | AC | 130 ms | 48764 KB |
2_047.txt | AC | 197 ms | 49276 KB |
2_048.txt | AC | 247 ms | 49276 KB |
2_049.txt | AC | 180 ms | 39036 KB |
2_050.txt | AC | 152 ms | 32892 KB |