結果

問題 No.472 平均順位
ユーザー htensaihtensai
提出日時 2020-01-30 13:42:48
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 1,559 bytes
コンパイル時間 3,866 ms
コンパイル使用メモリ 73,756 KB
実行使用メモリ 412,368 KB
最終ジャッジ日時 2023-10-14 08:24:47
合計ジャッジ時間 9,495 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,332 KB
testcase_01 AC 46 ms
49,264 KB
testcase_02 AC 46 ms
47,388 KB
testcase_03 AC 46 ms
49,684 KB
testcase_04 AC 55 ms
49,340 KB
testcase_05 AC 46 ms
49,272 KB
testcase_06 AC 49 ms
49,312 KB
testcase_07 AC 60 ms
50,988 KB
testcase_08 AC 91 ms
54,988 KB
testcase_09 AC 116 ms
62,164 KB
testcase_10 AC 156 ms
58,420 KB
testcase_11 AC 240 ms
77,368 KB
testcase_12 AC 213 ms
70,200 KB
testcase_13 AC 659 ms
122,068 KB
testcase_14 MLE -
testcase_15 AC 659 ms
122,380 KB
testcase_16 MLE -
testcase_17 MLE -
testcase_18 AC 120 ms
69,724 KB
testcase_19 AC 383 ms
83,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    static int[][] scores;
    static int[][] dp;
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] first = br.readLine().split(" ", 2);
        int n = Integer.parseInt(first[0]);
        int p = Integer.parseInt(first[1]);
        scores = new int[n][3];
        for (int i = 0; i < n; i++) {
            String[] line = br.readLine().split(" ", 3);
            for (int j = 0; j < 3; j++) {
                scores[i][j] = Integer.parseInt(line[j]);
            }
        }
        dp = new int[n][p + 1];
        System.out.println(dfw(n - 1, p) / (double)n);
    }
    
    static int dfw(int idx, int count) {
        if (count < 0) {
            return Integer.MAX_VALUE / 2;
        }
        if (idx < 0) {
            return 0;
        }
        if (dp[idx][count] != 0) {
            return dp[idx][count];
        }
        int min = Integer.MAX_VALUE / 2;
        if (idx * 3 >= count) {
            min = Math.min(min, dfw(idx - 1, count) + scores[idx][0]);
        }
        if (idx * 3 >= count - 1) {
            min = Math.min(min, dfw(idx - 1, count - 1) + scores[idx][1]);
        }
        if (idx * 3 >= count - 2) {
            min = Math.min(min, dfw(idx - 1, count - 2) + scores[idx][2]);
        }
        if (idx * 3 >= count - 3) {
            min = Math.min(min, dfw(idx - 1, count - 3) + 1);
        }
        dp[idx][count] = min;
        return min;
    }
}
0