結果

問題 No.27 板の準備
ユーザー tenten
提出日時 2021-12-02 15:38:56
言語 Java
(openjdk 23)
結果
AC  
実行時間 85 ms / 5,000 ms
コード長 2,026 bytes
コンパイル時間 2,333 ms
コンパイル使用メモリ 78,428 KB
実行使用メモリ 51,252 KB
最終ジャッジ日時 2024-07-05 01:56:12
合計ジャッジ時間 4,566 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int[] value = new int[4];
for (int i = 0; i < 4; i++) {
value[i] = sc.nextInt();
}
int min = Integer.MAX_VALUE;
for (int a = 30; a >= 3; a--) {
for (int b = a - 1; b >= 2; b--) {
for (int c = b - 1; c >= 1; c--) {
int[] counts = new int[31];
Arrays.fill(counts, Integer.MAX_VALUE / 10);
counts[0] = 0;
for (int i = 0; i + a <= 30; i++) {
counts[i + a] = Math.min(counts[i + a], counts[i] + 1);
}
for (int i = 0; i + b <= 30; i++) {
counts[i + b] = Math.min(counts[i + b], counts[i] + 1);
}
for (int i = 0; i + c <= 30; i++) {
counts[i + c] = Math.min(counts[i + c], counts[i] + 1);
}
int sum = 0;
for (int x : value) {
sum += counts[x];
}
min = Math.min(min, sum);
}
}
}
System.out.println(min);
}
}
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 {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0