結果

問題 No.27 板の準備
ユーザー takeya_okinotakeya_okino
提出日時 2017-07-06 13:34:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 178 ms / 5,000 ms
コード長 1,361 bytes
コンパイル時間 2,126 ms
コンパイル使用メモリ 74,484 KB
実行使用メモリ 61,668 KB
最終ジャッジ日時 2023-08-27 04:42:21
合計ジャッジ時間 6,267 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 173 ms
61,064 KB
testcase_01 AC 174 ms
59,328 KB
testcase_02 AC 171 ms
61,052 KB
testcase_03 AC 170 ms
61,072 KB
testcase_04 AC 169 ms
61,096 KB
testcase_05 AC 168 ms
61,344 KB
testcase_06 AC 174 ms
60,968 KB
testcase_07 AC 172 ms
61,108 KB
testcase_08 AC 170 ms
59,412 KB
testcase_09 AC 170 ms
60,728 KB
testcase_10 AC 170 ms
61,220 KB
testcase_11 AC 172 ms
60,916 KB
testcase_12 AC 176 ms
61,044 KB
testcase_13 AC 173 ms
60,980 KB
testcase_14 AC 173 ms
61,156 KB
testcase_15 AC 176 ms
61,668 KB
testcase_16 AC 178 ms
60,768 KB
testcase_17 AC 174 ms
60,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int[] v = new int[4];
    for(int i = 0; i < 4; i++) {
      v[i] = sc.nextInt();
    }
    int[][][][] dp = new int[31][31][31][31];
    for(int i = 1; i < 31; i++) {
      for(int j = 1; j < 31; j++) {
        for(int k = 1; k < 31; k++) {
          dp[i][j][k][0] = 0;
          for(int s = 1; s < 31; s++) {
            int m = Integer.MAX_VALUE;
            if(s - i >= 0 && dp[i][j][k][s - i] != -1) m = Math.min(m, 1 + dp[i][j][k][s - i]);
            if(s - j >= 0 && dp[i][j][k][s - j] != -1) m = Math.min(m, 1 + dp[i][j][k][s - j]);
            if(s - k >= 0 && dp[i][j][k][s - k] != -1) m = Math.min(m, 1 + dp[i][j][k][s - k]);
            if(m == Integer.MAX_VALUE) m = -1;
            dp[i][j][k][s] = m;
          }
        }
      }
    }
    int ans = Integer.MAX_VALUE;
    for(int i = 1; i < 31; i++) {
      for(int j = 1; j < 31; j++) {
        for(int k = 1; k < 31; k++) {
          int t = 0;
          for(int l = 0; l < 4; l++) {
            if(dp[i][j][k][v[l]] != -1) {
              t += dp[i][j][k][v[l]];
            } else {
              t = Integer.MAX_VALUE;
              break;
            }
          }
          ans = Math.min(ans, t);
        }
      }
    }
    System.out.println(ans);
  }
}
0