結果

問題 No.1111 コード進行
ユーザー tentententen
提出日時 2024-03-12 16:03:57
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,414 bytes
コンパイル時間 2,363 ms
コンパイル使用メモリ 81,744 KB
実行使用メモリ 125,856 KB
最終ジャッジ日時 2024-03-12 16:04:08
合計ジャッジ時間 9,777 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
53,976 KB
testcase_01 AC 48 ms
53,992 KB
testcase_02 AC 47 ms
53,996 KB
testcase_03 AC 47 ms
53,988 KB
testcase_04 AC 45 ms
53,996 KB
testcase_05 AC 49 ms
53,996 KB
testcase_06 AC 79 ms
56,792 KB
testcase_07 AC 78 ms
57,244 KB
testcase_08 AC 72 ms
54,660 KB
testcase_09 AC 67 ms
54,888 KB
testcase_10 AC 73 ms
56,508 KB
testcase_11 AC 53 ms
53,976 KB
testcase_12 AC 97 ms
58,604 KB
testcase_13 AC 56 ms
53,996 KB
testcase_14 AC 154 ms
63,016 KB
testcase_15 AC 54 ms
53,988 KB
testcase_16 AC 89 ms
57,164 KB
testcase_17 AC 59 ms
56,072 KB
testcase_18 AC 49 ms
53,992 KB
testcase_19 AC 47 ms
53,992 KB
testcase_20 AC 51 ms
54,004 KB
testcase_21 AC 51 ms
53,988 KB
testcase_22 AC 71 ms
59,000 KB
testcase_23 AC 54 ms
53,996 KB
testcase_24 AC 70 ms
56,240 KB
testcase_25 AC 119 ms
62,724 KB
testcase_26 WA -
testcase_27 AC 55 ms
53,988 KB
testcase_28 AC 120 ms
115,268 KB
testcase_29 AC 95 ms
79,052 KB
testcase_30 TLE -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static List<Map<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);
        }
        int ans = 0;
        dp = new int[n][300][k + 1];
        for (int[][] arr1 : dp) {
            for (int[] arr2 : arr1) {
                Arrays.fill(arr2, -1);
            }
        }
        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 v, int w) {
        if (w < 0) {
            return 0;
        }
        if (idx == 0) {
            if (w == 0) {
                return 1;
            } else {
                return 0;
            }
        }
        if (dp[idx][v][w] < 0) {
            dp[idx][v][w] = 0;
            for (int x : graph.get(v).keySet()) {
                dp[idx][v][w] += dfw(idx - 1, x, w - graph.get(v).get(x));
            } 
        }
        return dp[idx][v][w];
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0