結果
問題 |
No.27 板の準備
|
ユーザー |
![]() |
提出日時 | 2022-08-19 11:53:00 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 74 ms / 5,000 ms |
コード長 | 2,038 bytes |
コンパイル時間 | 2,293 ms |
コンパイル使用メモリ | 77,900 KB |
実行使用メモリ | 51,264 KB |
最終ジャッジ日時 | 2024-10-07 15:43:00 |
合計ジャッジ時間 | 3,845 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int[] sheets = new int[4]; for (int i = 0; i < 4; i++) { sheets[i] = sc.nextInt(); } int[] blocks = new int[3]; long ans = Long.MAX_VALUE; for (int a = 1; a <= 30; a++) { blocks[0] = a; for (int b = a + 1; b <= 30; b++) { blocks[1] = b; for (int c = b + 1; c <= 30; c++) { blocks[2] = c; long count = 0; int[] dp = new int[31]; for (int i = 0; i < 4; i++) { count += dfw(sheets[i], blocks, dp); } ans = Math.min(ans, count); } } } System.out.println(ans); } static int dfw(int x, int[] blocks, int[] dp) { if (x < 0) { return Integer.MAX_VALUE / 2; } if (x == 0) { return 0; } if (dp[x] == 0) { dp[x] = Integer.MAX_VALUE / 2; for (int i = 0; i < 3; i++) { dp[x] = Math.min(dp[x], dfw(x - blocks[i], blocks, dp) + 1); } } return dp[x]; } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }