結果

問題 No.842 初詣
ユーザー shinwisteriashinwisteria
提出日時 2019-08-30 14:44:48
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 782 bytes
コンパイル時間 3,415 ms
コンパイル使用メモリ 77,400 KB
実行使用メモリ 54,220 KB
最終ジャッジ日時 2024-05-01 06:25:02
合計ジャッジ時間 6,775 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
53,784 KB
testcase_01 AC 122 ms
53,812 KB
testcase_02 AC 124 ms
53,916 KB
testcase_03 AC 122 ms
53,996 KB
testcase_04 AC 124 ms
53,964 KB
testcase_05 AC 126 ms
54,076 KB
testcase_06 AC 128 ms
54,112 KB
testcase_07 WA -
testcase_08 AC 124 ms
54,108 KB
testcase_09 AC 122 ms
53,916 KB
testcase_10 AC 125 ms
54,116 KB
testcase_11 AC 128 ms
54,116 KB
testcase_12 AC 125 ms
53,988 KB
testcase_13 AC 113 ms
52,936 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 124 ms
54,192 KB
testcase_17 AC 127 ms
53,968 KB
testcase_18 AC 124 ms
54,072 KB
testcase_19 AC 130 ms
54,116 KB
testcase_20 AC 112 ms
53,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package con_level_1half;
import java.util.Scanner;
public class Con842 {
	static int[] num = new int[6];
	static int[] gold = {500,100,50,10,5,1};

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		for(int i = 0;i < 6;i++){
			num[i] = s.nextInt();
		}
		int g = s.nextInt();
		s.close();
		int t = rec(0,g);
		if(t == 1){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}

		}

	static int rec(int k, int tot){    //k:goldとnumの番号、tot:残りの合計
		int tf = 0;

		if(tot % gold[k] == 0){
			if(tot / gold[k] <= num[k]){
				tf = 1;
			}else{
				if(k == 5){
					tf = 0;
				}else{
					tf = rec(k + 1 ,tot - gold[k] + num[k]);
				}
			}
		}else{
			tf = rec(k + 1 , tot - gold[k] * num[k]);
		}
		return tf;
	}
}
0