結果
問題 | No.842 初詣 |
ユーザー |
|
提出日時 | 2019-08-30 14:49:17 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 136 ms / 2,000 ms |
コード長 | 867 bytes |
コンパイル時間 | 4,942 ms |
コンパイル使用メモリ | 77,700 KB |
実行使用メモリ | 54,420 KB |
最終ジャッジ日時 | 2024-11-21 10:24:02 |
合計ジャッジ時間 | 8,371 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
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; } }