結果

問題 No.1111 コード進行
ユーザー tentententen
提出日時 2023-03-17 15:14:19
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,767 bytes
コンパイル時間 2,577 ms
コンパイル使用メモリ 84,740 KB
実行使用メモリ 122,824 KB
最終ジャッジ日時 2023-10-18 13:41:05
合計ジャッジ時間 10,008 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
53,680 KB
testcase_01 AC 54 ms
52,392 KB
testcase_02 AC 55 ms
53,576 KB
testcase_03 AC 55 ms
53,568 KB
testcase_04 AC 56 ms
53,572 KB
testcase_05 AC 59 ms
53,572 KB
testcase_06 AC 80 ms
56,692 KB
testcase_07 AC 92 ms
56,968 KB
testcase_08 AC 82 ms
54,168 KB
testcase_09 AC 91 ms
55,044 KB
testcase_10 AC 69 ms
56,308 KB
testcase_11 AC 68 ms
52,588 KB
testcase_12 AC 116 ms
58,604 KB
testcase_13 AC 68 ms
53,700 KB
testcase_14 AC 159 ms
62,064 KB
testcase_15 AC 60 ms
53,580 KB
testcase_16 AC 102 ms
56,924 KB
testcase_17 AC 66 ms
55,732 KB
testcase_18 AC 58 ms
53,580 KB
testcase_19 AC 57 ms
53,572 KB
testcase_20 AC 61 ms
53,584 KB
testcase_21 AC 57 ms
53,580 KB
testcase_22 AC 71 ms
58,048 KB
testcase_23 AC 67 ms
53,588 KB
testcase_24 AC 80 ms
56,200 KB
testcase_25 AC 137 ms
61,948 KB
testcase_26 WA -
testcase_27 AC 60 ms
53,604 KB
testcase_28 AC 134 ms
114,572 KB
testcase_29 AC 109 ms
78,240 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.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));
            }
        }
        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