結果

問題 No.1111 コード進行
ユーザー tentententen
提出日時 2023-03-17 15:15:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 657 ms / 2,000 ms
コード長 2,805 bytes
コンパイル時間 2,627 ms
コンパイル使用メモリ 84,860 KB
実行使用メモリ 197,840 KB
最終ジャッジ日時 2023-10-18 13:41:18
合計ジャッジ時間 11,799 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
53,588 KB
testcase_01 AC 56 ms
53,576 KB
testcase_02 AC 55 ms
53,584 KB
testcase_03 AC 54 ms
53,584 KB
testcase_04 AC 55 ms
53,580 KB
testcase_05 AC 59 ms
53,584 KB
testcase_06 AC 80 ms
57,040 KB
testcase_07 AC 79 ms
56,508 KB
testcase_08 AC 84 ms
54,176 KB
testcase_09 AC 89 ms
54,536 KB
testcase_10 AC 81 ms
56,460 KB
testcase_11 AC 67 ms
52,928 KB
testcase_12 AC 112 ms
58,292 KB
testcase_13 AC 64 ms
53,692 KB
testcase_14 AC 162 ms
62,736 KB
testcase_15 AC 60 ms
53,588 KB
testcase_16 AC 91 ms
57,120 KB
testcase_17 AC 77 ms
55,648 KB
testcase_18 AC 59 ms
53,596 KB
testcase_19 AC 57 ms
53,588 KB
testcase_20 AC 59 ms
53,612 KB
testcase_21 AC 57 ms
53,596 KB
testcase_22 AC 67 ms
58,620 KB
testcase_23 AC 66 ms
53,600 KB
testcase_24 AC 79 ms
56,212 KB
testcase_25 AC 130 ms
61,360 KB
testcase_26 AC 141 ms
62,564 KB
testcase_27 AC 61 ms
53,604 KB
testcase_28 AC 134 ms
114,560 KB
testcase_29 AC 105 ms
77,960 KB
testcase_30 AC 391 ms
116,044 KB
testcase_31 AC 97 ms
59,540 KB
testcase_32 AC 395 ms
114,900 KB
testcase_33 AC 504 ms
99,168 KB
testcase_34 AC 121 ms
91,420 KB
testcase_35 AC 140 ms
115,124 KB
testcase_36 AC 142 ms
116,536 KB
testcase_37 AC 132 ms
67,144 KB
testcase_38 AC 366 ms
77,448 KB
testcase_39 AC 657 ms
119,408 KB
testcase_40 AC 631 ms
142,456 KB
testcase_41 AC 137 ms
116,796 KB
testcase_42 AC 132 ms
78,360 KB
testcase_43 AC 534 ms
96,616 KB
testcase_44 AC 92 ms
66,504 KB
testcase_45 AC 116 ms
89,340 KB
testcase_46 AC 123 ms
59,220 KB
testcase_47 AC 292 ms
197,840 KB
testcase_48 AC 143 ms
62,140 KB
testcase_49 AC 85 ms
56,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static ArrayList<HashMap<Integer, Integer>> graph = new ArrayList<>();
    static int[][][] dp;
    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();
        for (int i = 0; i < 300; i++) {
            graph.add(new HashMap<>());
        }
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            int c = sc.nextInt();
            graph.get(b).put(a, c);
        }
        dp = new int[n][300][k + 1];
        for (int[][] arr1 : dp) {
            for (int[] arr2 : arr1) {
                Arrays.fill(arr2, -1);
            }
        }
        int ans = 0;
        for (int i = 0; i < 300; i++) {
            ans += dfw(n - 1, i, k);
            ans %= MOD;
        }
        System.out.println(ans);
    }
    
    static int dfw(int idx, int c, int v) {
        if (v < 0) {
            return 0;
        }
        if (idx == 0) {
            if (v == 0) {
                return 1;
            } else {
                return 0;
            }
        }
        if (dp[idx][c][v] < 0) {
            dp[idx][c][v] = 0;
            for (int x : graph.get(c).keySet()) {
                dp[idx][c][v] += dfw(idx - 1, x, v - graph.get(c).get(x));
                dp[idx][c][v] %= MOD;
            }
        }
        return dp[idx][c][v];
    }
    
}
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