結果

問題 No.472 平均順位
ユーザー takeya_okinotakeya_okino
提出日時 2017-07-05 19:22:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 903 ms / 2,000 ms
コード長 1,247 bytes
コンパイル時間 2,169 ms
コンパイル使用メモリ 77,680 KB
実行使用メモリ 48,276 KB
最終ジャッジ日時 2024-04-15 18:16:50
合計ジャッジ時間 9,564 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
40,212 KB
testcase_01 AC 114 ms
40,112 KB
testcase_02 AC 110 ms
40,204 KB
testcase_03 AC 111 ms
40,000 KB
testcase_04 AC 155 ms
42,376 KB
testcase_05 AC 106 ms
39,884 KB
testcase_06 AC 130 ms
41,260 KB
testcase_07 AC 148 ms
42,048 KB
testcase_08 AC 208 ms
44,680 KB
testcase_09 AC 303 ms
47,308 KB
testcase_10 AC 279 ms
47,368 KB
testcase_11 AC 360 ms
47,144 KB
testcase_12 AC 334 ms
47,092 KB
testcase_13 AC 510 ms
48,276 KB
testcase_14 AC 835 ms
48,064 KB
testcase_15 AC 514 ms
48,096 KB
testcase_16 AC 903 ms
48,084 KB
testcase_17 AC 890 ms
46,740 KB
testcase_18 AC 320 ms
47,548 KB
testcase_19 AC 396 ms
47,756 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[j]はコンテストiまでで正解数がちょうどj問の場合の順位の和の最小値(有り得ない場合は0とする)
    int[] dp = new int[P + 1];
    dp[0] = a[0];
    if(1 < P + 1) dp[1] = b[0];
    if(2 < P + 1) dp[2] = c[0];
    if(3 < P + 1) dp[3] = 1;
    int[] arr = dp.clone();
    for(int i = 1; i < N; i++) {
      for(int j = 0; j < P + 1; j++) {
        int min = Integer.MAX_VALUE;
        if(arr[j] != 0) min = Math.min(min, a[i] + arr[j]);
        if(j >= 1 && arr[j - 1] != 0) min = Math.min(min, b[i] + arr[j - 1]);
        if(j >= 2 && arr[j - 2] != 0) min = Math.min(min, c[i] + arr[j - 2]);
        if(j >= 3 && arr[j - 3] != 0) min = Math.min(min, 1 + arr[j - 3]);
        if(min == Integer.MAX_VALUE) min = 0;
        dp[j] = min;
      }
      arr = dp.clone();
    }
    System.out.println((double)dp[P] / (double)N);
  }
}
0