結果

問題 No.842 初詣
ユーザー GrenacheGrenache
提出日時 2019-06-28 22:12:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 1,126 bytes
コンパイル時間 3,810 ms
コンパイル使用メモリ 76,232 KB
実行使用メモリ 59,924 KB
最終ジャッジ日時 2023-09-14 22:06:14
合計ジャッジ時間 8,413 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,500 KB
testcase_01 AC 131 ms
55,876 KB
testcase_02 AC 132 ms
55,760 KB
testcase_03 AC 134 ms
55,744 KB
testcase_04 AC 155 ms
55,928 KB
testcase_05 AC 162 ms
57,800 KB
testcase_06 AC 141 ms
56,088 KB
testcase_07 AC 213 ms
59,484 KB
testcase_08 AC 141 ms
55,936 KB
testcase_09 AC 138 ms
55,504 KB
testcase_10 AC 229 ms
59,436 KB
testcase_11 AC 132 ms
55,828 KB
testcase_12 AC 210 ms
59,716 KB
testcase_13 AC 157 ms
55,828 KB
testcase_14 AC 161 ms
57,592 KB
testcase_15 AC 141 ms
55,868 KB
testcase_16 AC 161 ms
58,092 KB
testcase_17 AC 176 ms
58,128 KB
testcase_18 AC 214 ms
59,424 KB
testcase_19 AC 159 ms
57,788 KB
testcase_20 AC 255 ms
59,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder842 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int[] abcdef = new int[6];
		for (int i = 0; i < 6; i++) {
			abcdef[i] = sc.nextInt();
		}
		
		int g = sc.nextInt();

		Deque<List<Integer>> st = new ArrayDeque<>();
		st.push(new ArrayList<>());
		while (!st.isEmpty()) {
			List<Integer> e = st.pop();
			
			int j = e.size();
			
			if (j == 6) {
				int sum = 500 * e.get(0) + 100 * e.get(1) + 50 * e.get(2) + 10 * e.get(3) + 5 * e.get(4) + e.get(5);
				
				if (sum == g) {
					pr.println("YES");
					return;
				}
			} else {
				for (int i = 0; i <= abcdef[j]; i++) {
					List<Integer> tmp = new ArrayList<>(e);
					tmp.add(i);
					st.push(tmp);
				}
			}
		}
		
		pr.println("NO");
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}
0