結果

問題 No.1111 コード進行
ユーザー tentententen
提出日時 2023-04-25 08:17:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 416 ms / 2,000 ms
コード長 2,556 bytes
コンパイル時間 3,411 ms
コンパイル使用メモリ 84,668 KB
実行使用メモリ 181,996 KB
最終ジャッジ日時 2024-04-26 15:56:02
合計ジャッジ時間 11,186 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
37,184 KB
testcase_01 AC 51 ms
37,004 KB
testcase_02 AC 58 ms
37,028 KB
testcase_03 AC 52 ms
37,320 KB
testcase_04 AC 53 ms
37,420 KB
testcase_05 AC 52 ms
38,484 KB
testcase_06 AC 78 ms
40,060 KB
testcase_07 AC 77 ms
39,908 KB
testcase_08 AC 75 ms
38,708 KB
testcase_09 AC 67 ms
39,120 KB
testcase_10 AC 62 ms
40,372 KB
testcase_11 AC 58 ms
37,648 KB
testcase_12 AC 78 ms
40,824 KB
testcase_13 AC 58 ms
38,892 KB
testcase_14 AC 99 ms
45,364 KB
testcase_15 AC 60 ms
37,692 KB
testcase_16 AC 78 ms
41,204 KB
testcase_17 AC 60 ms
40,668 KB
testcase_18 AC 55 ms
37,952 KB
testcase_19 AC 53 ms
37,884 KB
testcase_20 AC 54 ms
38,252 KB
testcase_21 AC 58 ms
37,360 KB
testcase_22 AC 64 ms
45,052 KB
testcase_23 AC 59 ms
38,944 KB
testcase_24 AC 64 ms
39,312 KB
testcase_25 AC 94 ms
45,980 KB
testcase_26 AC 80 ms
41,204 KB
testcase_27 AC 60 ms
37,556 KB
testcase_28 AC 172 ms
103,284 KB
testcase_29 AC 139 ms
68,836 KB
testcase_30 AC 180 ms
77,956 KB
testcase_31 AC 63 ms
44,868 KB
testcase_32 AC 218 ms
77,804 KB
testcase_33 AC 193 ms
68,812 KB
testcase_34 AC 150 ms
79,904 KB
testcase_35 AC 212 ms
104,852 KB
testcase_36 AC 334 ms
104,412 KB
testcase_37 AC 198 ms
58,028 KB
testcase_38 AC 171 ms
56,176 KB
testcase_39 AC 226 ms
78,904 KB
testcase_40 AC 245 ms
103,328 KB
testcase_41 AC 237 ms
121,236 KB
testcase_42 AC 245 ms
76,116 KB
testcase_43 AC 230 ms
69,160 KB
testcase_44 AC 121 ms
54,700 KB
testcase_45 AC 196 ms
78,556 KB
testcase_46 AC 128 ms
45,432 KB
testcase_47 AC 416 ms
181,996 KB
testcase_48 AC 132 ms
45,428 KB
testcase_49 AC 134 ms
45,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        ArrayList<HashMap<Integer, Integer>> graph = new ArrayList<>();
        for (int i = 0; i < 300; i++) {
            graph.add(new HashMap<>());
        }
        for (int i = 0; i < m; i++) {
            graph.get(sc.nextInt() - 1).put(sc.nextInt() - 1, sc.nextInt());
        }
        int[][][] dp = new int[n][300][k + 1];
        for (int i = 0; i < 300; i++) {
            dp[0][i][0] = 1;
        }
        for (int i = 0; i < n - 1; i++) {
            for (int j = 0; j < 300; j++) {
                for (int x : graph.get(j).keySet()) {
                    int value = graph.get(j).get(x);
                    for (int s = k - value; s >= 0; s--) {
                        dp[i + 1][x][s + value] += dp[i][j][s];
                        dp[i + 1][x][s + value] %= MOD;
                    }
                }
            }
        }
        int ans = 0;
        for (int i = 0; i < 300; i++) {
            ans += dp[n - 1][i][k];
            ans %= MOD;
        }
        System.out.println(ans);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0