結果

問題 No.842 初詣
ユーザー shinwisteriashinwisteria
提出日時 2019-08-30 14:44:48
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 782 bytes
コンパイル時間 3,434 ms
コンパイル使用メモリ 77,292 KB
実行使用メモリ 54,364 KB
最終ジャッジ日時 2024-11-21 08:25:28
合計ジャッジ時間 7,273 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 3
権限があれば一括ダウンロードができます

ソースコード

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