結果

問題 No.842 初詣
ユーザー shinwisteriashinwisteria
提出日時 2019-08-30 14:49:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 867 bytes
コンパイル時間 4,231 ms
コンパイル使用メモリ 77,200 KB
実行使用メモリ 54,252 KB
最終ジャッジ日時 2024-05-01 07:38:57
合計ジャッジ時間 7,302 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
52,860 KB
testcase_01 AC 99 ms
52,896 KB
testcase_02 AC 96 ms
52,596 KB
testcase_03 AC 100 ms
54,252 KB
testcase_04 AC 101 ms
52,544 KB
testcase_05 AC 109 ms
53,732 KB
testcase_06 AC 108 ms
53,984 KB
testcase_07 AC 114 ms
54,100 KB
testcase_08 AC 110 ms
53,744 KB
testcase_09 AC 109 ms
53,888 KB
testcase_10 AC 119 ms
54,052 KB
testcase_11 AC 113 ms
53,780 KB
testcase_12 AC 119 ms
53,748 KB
testcase_13 AC 124 ms
54,028 KB
testcase_14 AC 113 ms
53,844 KB
testcase_15 AC 121 ms
53,908 KB
testcase_16 AC 104 ms
52,928 KB
testcase_17 AC 110 ms
53,072 KB
testcase_18 AC 123 ms
53,732 KB
testcase_19 AC 125 ms
54,144 KB
testcase_20 AC 101 ms
53,092 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{
			if(tot / gold[k] <= num[k]){
				tf = rec(k + 1 , tot % gold[k]);
			}else{
				tf = rec(k + 1 , tot - gold[k] *  num[k]);
			}
		}
		return tf;
	}
}
0