結果

問題 No.1111 コード進行
ユーザー shojin_proshojin_pro
提出日時 2020-07-10 22:49:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 623 ms / 2,000 ms
コード長 3,137 bytes
コンパイル時間 2,324 ms
コンパイル使用メモリ 79,964 KB
実行使用メモリ 255,524 KB
最終ジャッジ日時 2024-04-19 18:00:48
合計ジャッジ時間 9,424 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
37,232 KB
testcase_01 AC 51 ms
37,236 KB
testcase_02 AC 52 ms
36,952 KB
testcase_03 AC 53 ms
37,156 KB
testcase_04 AC 51 ms
37,060 KB
testcase_05 AC 52 ms
40,108 KB
testcase_06 AC 67 ms
45,400 KB
testcase_07 AC 65 ms
45,520 KB
testcase_08 AC 61 ms
38,688 KB
testcase_09 AC 60 ms
41,124 KB
testcase_10 AC 59 ms
44,596 KB
testcase_11 AC 55 ms
38,692 KB
testcase_12 AC 73 ms
45,376 KB
testcase_13 AC 54 ms
40,432 KB
testcase_14 AC 95 ms
46,288 KB
testcase_15 AC 56 ms
37,944 KB
testcase_16 AC 97 ms
45,240 KB
testcase_17 AC 56 ms
44,604 KB
testcase_18 AC 53 ms
38,608 KB
testcase_19 AC 51 ms
38,352 KB
testcase_20 AC 53 ms
39,664 KB
testcase_21 AC 53 ms
37,304 KB
testcase_22 AC 60 ms
48,484 KB
testcase_23 AC 55 ms
40,292 KB
testcase_24 AC 59 ms
44,768 KB
testcase_25 AC 82 ms
50,340 KB
testcase_26 AC 93 ms
46,260 KB
testcase_27 AC 55 ms
38,528 KB
testcase_28 AC 179 ms
179,996 KB
testcase_29 AC 135 ms
109,100 KB
testcase_30 AC 180 ms
121,772 KB
testcase_31 AC 67 ms
52,816 KB
testcase_32 AC 217 ms
121,920 KB
testcase_33 AC 188 ms
81,184 KB
testcase_34 AC 152 ms
121,612 KB
testcase_35 AC 165 ms
138,976 KB
testcase_36 AC 329 ms
179,612 KB
testcase_37 AC 151 ms
74,116 KB
testcase_38 AC 143 ms
66,064 KB
testcase_39 AC 259 ms
121,568 KB
testcase_40 AC 259 ms
137,136 KB
testcase_41 AC 198 ms
180,392 KB
testcase_42 AC 197 ms
109,004 KB
testcase_43 AC 187 ms
81,612 KB
testcase_44 AC 118 ms
66,560 KB
testcase_45 AC 187 ms
121,716 KB
testcase_46 AC 76 ms
42,336 KB
testcase_47 AC 623 ms
255,524 KB
testcase_48 AC 89 ms
50,200 KB
testcase_49 AC 88 ms
42,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
 
public class Main {
    static int n,m,k;
    static ArrayList<Music> li;
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        long mod = (long)Math.pow(10,9)+7;
        n = sc.nextInt();
        m = sc.nextInt();
        k = sc.nextInt();
        li = new ArrayList<>();
        for(int i = 0; i < m; i++){
            int p = sc.nextInt()-1;
            int q = sc.nextInt()-1;
            int c = sc.nextInt();
            li.add(new Music(p,q,c));
        }
        Collections.sort(li);
        long[][][] dp = new long[300][n+1][k+2];
        for(int i = 0; i < 300; i++){
            dp[i][1][0] = 1;
        }
        for(int i = 2; i <= n; i++){
            for(Music m : li){
                for(int j = k-m.c; j >= 0; j--){
                    dp[m.q][i][j+m.c] += dp[m.p][i-1][j];
                    dp[m.q][i][j+m.c] %= mod;
                }
            }
        }
        long ans = 0;
        for(int i = 0; i < 300; i++){
            ans += dp[i][n][k];
            ans %= mod;
        }
        System.out.println(ans);
    }
}

class Music implements Comparable<Music>{
    int p,q,c;
    public Music(int p, int q, int c){
        this.p = p;
        this.q = q;
        this.c = c;
    } 
    
    public int compareTo(Music m){
        if(this.c > m.c){
            return -1;
        }else if(this.c < m.c){
            return 1;
        }else{
            return 0;
        }
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}
0