結果

問題 No.472 平均順位
ユーザー takeya_okinotakeya_okino
提出日時 2017-07-05 19:06:16
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 1,273 bytes
コンパイル時間 2,206 ms
コンパイル使用メモリ 77,220 KB
実行使用メモリ 352,888 KB
最終ジャッジ日時 2024-04-15 18:16:32
合計ジャッジ時間 11,940 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
53,728 KB
testcase_01 AC 137 ms
54,216 KB
testcase_02 AC 139 ms
54,288 KB
testcase_03 AC 139 ms
53,788 KB
testcase_04 AC 179 ms
54,372 KB
testcase_05 AC 139 ms
54,364 KB
testcase_06 AC 159 ms
54,224 KB
testcase_07 AC 171 ms
54,092 KB
testcase_08 AC 240 ms
57,036 KB
testcase_09 AC 335 ms
62,892 KB
testcase_10 AC 311 ms
60,728 KB
testcase_11 AC 418 ms
85,604 KB
testcase_12 AC 390 ms
78,576 KB
testcase_13 AC 613 ms
130,008 KB
testcase_14 MLE -
testcase_15 AC 587 ms
129,844 KB
testcase_16 MLE -
testcase_17 MLE -
testcase_18 AC 366 ms
70,276 KB
testcase_19 AC 465 ms
87,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int P = sc.nextInt();
    int[] a = new int[N];
    int[] b = new int[N];
    int[] c = new int[N];
    for(int i = 0; i < N; i++) {
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
      c[i] = sc.nextInt();
    }
    // dp[i][j]はコンテストiまでで正解数がちょうどj問の場合の順位の和の最小値(有り得ない場合は0とする)
    int[][] dp = new int[N][P + 1];
    dp[0][0] = a[0];
    if(1 < P + 1) dp[0][1] = b[0];
    if(2 < P + 1) dp[0][2] = c[0];
    if(3 < P + 1) dp[0][3] = 1;
    for(int i = 1; i < N; i++) {
      for(int j = 0; j < P + 1; j++) {
        int min = Integer.MAX_VALUE;
        if(dp[i - 1][j] != 0) min = Math.min(min, a[i] + dp[i - 1][j]);
        if(j >= 1 && dp[i - 1][j - 1] != 0) min = Math.min(min, b[i] + dp[i - 1][j - 1]);
        if(j >= 2 && dp[i - 1][j - 2] != 0) min = Math.min(min, c[i] + dp[i - 1][j - 2]);
        if(j >= 3 && dp[i - 1][j - 3] != 0) min = Math.min(min, 1 + dp[i - 1][j - 3]);
        if(min == Integer.MAX_VALUE) min = 0;
        dp[i][j] = min;
      }
    }
    System.out.println((double)dp[N - 1][P] / (double)N);
  }
}
0