結果

問題 No.914 Omiyage
ユーザー bal4ubal4u
提出日時 2019-10-27 15:55:44
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,006 bytes
コンパイル時間 195 ms
コンパイル使用メモリ 30,876 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 21:19:21
合計ジャッジ時間 913 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yuki 914 Omiyage
// 2019.10.27 bal4u

#include <stdio.h>
#include <ctype.h>
#include <string.h>

int getchar_unlocked(void);
#define gc() getchar_unlocked()

int in() {   // 非負整数の入力
	int n = 0; int c;
	do c = gc(); while (isspace(c));
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

inline static int chmax(int *a, int b) { if (*a < b) *a = b; }

char dp[12][505];
int A[12];

int main()
{
	int i, j, k, f, N, M, K, ma;
	
    N = in(), M = in(), K = in();
    dp[0][0] = 1, ma = 0;
    for (i = 1; i <= N; ++i) {
        for (j = 0; j < M; ++j) A[j] = in();
        f = 0;
        for (k = ma; k >= 0; --k) if (dp[i-1][k]) {
            for (j = M-1; j >= 0; j--) {
                if (k+A[j] <= K) {
                    dp[i][k+A[j]] = 1, f = 1;
                    chmax(&ma, k+A[j]);
                }
            }
        }
        if (f == 0) { puts("-1"); return 0; }
    }
    for (i = K; i >= 0; --i) if (dp[N][i]) break;
    printf("%d\n", K-i);
	return 0;
}
0