結果

問題 No.472 平均順位
ユーザー htensaihtensai
提出日時 2020-01-08 17:24:32
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,456 bytes
コンパイル時間 2,197 ms
コンパイル使用メモリ 76,104 KB
実行使用メモリ 667,376 KB
最終ジャッジ日時 2023-08-15 00:41:01
合計ジャッジ時間 13,453 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
33,388 KB
testcase_01 AC 40 ms
33,320 KB
testcase_02 AC 40 ms
33,216 KB
testcase_03 AC 41 ms
33,312 KB
testcase_04 AC 78 ms
35,484 KB
testcase_05 AC 41 ms
33,408 KB
testcase_06 AC 52 ms
34,036 KB
testcase_07 AC 86 ms
37,124 KB
testcase_08 AC 181 ms
50,112 KB
testcase_09 AC 634 ms
113,856 KB
testcase_10 AC 756 ms
135,952 KB
testcase_11 TLE -
testcase_12 MLE -
testcase_13 MLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static HashMap<Integer, Integer>[] dp;
    static int[][] contests;
    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]);
        dp = new HashMap[n + 1];
        contests = new int[n + 1][3];
        for (int i = 1; i <= n; i++) {
            String[] line = br.readLine().split(" ", 3);
            for (int j = 0; j < 3; j++) {
                contests[i][j] = Integer.parseInt(line[j]);
            }
            dp[i] = new HashMap<Integer, Integer>();
        }
        System.out.println(dfw(n, 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].containsKey(count)) {
            return dp[idx].get(count);
        }
        int ans = Integer.MAX_VALUE;
        for (int i = 0; i < 3; i++) {
            if (count - i > (idx - 1) * 3) {
                continue;
            }
            ans = Math.min(ans, dfw(idx - 1, count - i) + contests[idx][i]);
        }
        ans = Math.min(ans, dfw(idx - 1, count - 3) + 1);
        dp[idx].put(count, ans);
        return ans;
    }
}
0