結果
問題 |
No.634 硬貨の枚数1
|
ユーザー |
![]() |
提出日時 | 2019-12-19 12:15:30 |
言語 | Java (openjdk 23) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,036 bytes |
コンパイル時間 | 2,102 ms |
コンパイル使用メモリ | 78,704 KB |
実行使用メモリ | 128,292 KB |
最終ジャッジ日時 | 2024-07-07 01:06:17 |
合計ジャッジ時間 | 10,207 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 11 TLE * 1 -- * 63 |
ソースコード
import java.util.*; import java.io.*; public class Main { static int[] coins; static HashMap<Integer, Integer>[] maps; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); coins = new int[5000]; maps = new HashMap[5000]; for (int i = 1; i < 5000; i++) { coins[i] = i * (i + 1) / 2; maps[i] = new HashMap<Integer, Integer>(); } System.out.println(dfw(4999, n)); } static int dfw(int idx, int value) { if (value < 0) { return Integer.MAX_VALUE / 10; } if (value % coins[idx] == 0) { return value / coins[idx]; } if (maps[idx].containsKey(value)) { return maps[idx].get(value); } int min = Math.min(dfw(idx - 1, value), 1 + dfw(idx - 1, value - coins[idx])); maps[idx].put(value, min); return min; } }