結果

問題 No.914 Omiyage
ユーザー 37zigen37zigen
提出日時 2020-03-10 04:32:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 767 bytes
コンパイル時間 2,070 ms
コンパイル使用メモリ 73,944 KB
実行使用メモリ 57,916 KB
最終ジャッジ日時 2023-08-10 00:27:04
合計ジャッジ時間 6,709 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
55,732 KB
testcase_01 AC 137 ms
56,040 KB
testcase_02 AC 135 ms
55,460 KB
testcase_03 AC 135 ms
55,952 KB
testcase_04 AC 134 ms
55,700 KB
testcase_05 AC 125 ms
55,780 KB
testcase_06 AC 124 ms
55,692 KB
testcase_07 AC 121 ms
56,040 KB
testcase_08 AC 130 ms
55,808 KB
testcase_09 AC 123 ms
55,904 KB
testcase_10 AC 127 ms
53,716 KB
testcase_11 AC 125 ms
55,688 KB
testcase_12 AC 129 ms
55,956 KB
testcase_13 AC 133 ms
55,696 KB
testcase_14 AC 132 ms
55,636 KB
testcase_15 AC 127 ms
55,908 KB
testcase_16 AC 127 ms
57,916 KB
testcase_17 AC 133 ms
55,680 KB
testcase_18 AC 124 ms
55,476 KB
testcase_19 AC 125 ms
56,060 KB
testcase_20 AC 125 ms
55,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		int K=sc.nextInt();
		int[][] A=new int[N][M];
		boolean[][] dp=new boolean[N+1][K+1];
		for(int i=0;i<A.length;++i) {
			for(int j=0;j<A[i].length;++j) {
				A[i][j]=sc.nextInt();
			}
		}
		dp[0][0]=true;
		for(int i=0;i<N;++i) {
			for(int cur=0;cur<=K;++cur) {
				if(!dp[i][cur])continue;
				for(int next=0;next<M;++next) {
					if(cur+A[i][next]<=K)
						dp[i+1][cur+A[i][next]]|=dp[i][cur];
				}
			}
		}
		int ans=-1;
		for(int i=1;i<=K;++i)if(dp[N][i])ans=Math.max(ans, i);
		System.out.println(ans==-1?-1:(K-ans));
	}
}


0