結果

問題 No.1111 コード進行
ユーザー sca1lsca1l
提出日時 2020-07-20 22:10:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 533 ms / 2,000 ms
コード長 2,083 bytes
コンパイル時間 2,246 ms
コンパイル使用メモリ 76,968 KB
実行使用メモリ 193,740 KB
最終ジャッジ日時 2023-08-26 02:17:53
合計ジャッジ時間 19,768 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 255 ms
191,284 KB
testcase_01 AC 259 ms
191,848 KB
testcase_02 AC 255 ms
191,740 KB
testcase_03 AC 252 ms
192,176 KB
testcase_04 AC 248 ms
191,676 KB
testcase_05 AC 251 ms
191,496 KB
testcase_06 AC 277 ms
192,068 KB
testcase_07 AC 315 ms
192,524 KB
testcase_08 AC 299 ms
192,328 KB
testcase_09 AC 312 ms
193,056 KB
testcase_10 AC 266 ms
191,728 KB
testcase_11 AC 299 ms
191,964 KB
testcase_12 AC 317 ms
193,060 KB
testcase_13 AC 265 ms
192,260 KB
testcase_14 AC 329 ms
192,516 KB
testcase_15 AC 277 ms
191,976 KB
testcase_16 AC 329 ms
192,888 KB
testcase_17 AC 260 ms
191,720 KB
testcase_18 AC 254 ms
191,672 KB
testcase_19 AC 255 ms
191,288 KB
testcase_20 AC 262 ms
191,720 KB
testcase_21 AC 258 ms
191,484 KB
testcase_22 AC 258 ms
191,328 KB
testcase_23 AC 276 ms
192,284 KB
testcase_24 AC 261 ms
191,672 KB
testcase_25 AC 348 ms
193,124 KB
testcase_26 AC 321 ms
191,288 KB
testcase_27 AC 277 ms
191,896 KB
testcase_28 AC 255 ms
193,740 KB
testcase_29 AC 263 ms
192,204 KB
testcase_30 AC 310 ms
193,160 KB
testcase_31 AC 273 ms
192,844 KB
testcase_32 AC 365 ms
192,808 KB
testcase_33 AC 406 ms
192,996 KB
testcase_34 AC 257 ms
191,604 KB
testcase_35 AC 262 ms
191,588 KB
testcase_36 AC 305 ms
192,256 KB
testcase_37 AC 317 ms
192,500 KB
testcase_38 AC 391 ms
192,840 KB
testcase_39 AC 449 ms
193,288 KB
testcase_40 AC 495 ms
193,032 KB
testcase_41 AC 268 ms
191,552 KB
testcase_42 AC 342 ms
192,716 KB
testcase_43 AC 533 ms
193,732 KB
testcase_44 AC 274 ms
191,888 KB
testcase_45 AC 267 ms
191,660 KB
testcase_46 AC 322 ms
193,212 KB
testcase_47 AC 321 ms
193,580 KB
testcase_48 AC 325 ms
193,020 KB
testcase_49 AC 308 ms
192,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main{
    
    static final int MOD = (int)1e9+7;
    static final int MAX = 301;
    static int n;
    static int m;
    static int k;
    static ArrayList<Integer>[] graph;
    static ArrayList<Integer>[] complexity;
    static int[][][] memo;
    
    public static int dfs(int now, int cmp, int cnt){
        if(cmp <= k && memo[now][cmp][cnt] != -1){
            return memo[now][cmp][cnt];
        }
        
        if(cnt == n || cmp > k){
            //System.out.println(cnt + " : " + cmp);
            if(cnt == n && cmp == k){
                return 1;
            }else{
                return 0;
            }
        }
        
        int ret = 0;
        for(int i=0; i<graph[now].size(); i++){
            int next = graph[now].get(i);
            int cmpsum = complexity[now].get(i) + cmp;
            ret += dfs(next, cmpsum, cnt+1);
            ret %= MOD;
        }
        
        memo[now][cmp][cnt] = ret;
        return memo[now][cmp][cnt];
    }
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        n = Integer.parseInt(sc.next());
        m = Integer.parseInt(sc.next());
        k = Integer.parseInt(sc.next());
        
        memo = new int[MAX][MAX][MAX];
        for(int i=0; i<MAX; i++){
            for(int j=0; j<MAX; j++){
                Arrays.fill(memo[i][j], -1);
            }
        }
        
        graph = new ArrayList[MAX];
        complexity = new ArrayList[MAX];
        for(int i=0; i<MAX; i++){
            graph[i] = new ArrayList<>();
            complexity[i] = new ArrayList<>();
        }
        for(int i=0; i<m; i++){
            int p = Integer.parseInt(sc.next())-1;
            int q = Integer.parseInt(sc.next())-1;
            int c = Integer.parseInt(sc.next());
            
            graph[p].add(q);
            complexity[p].add(c);
        }
        
        int ans = 0;
        for(int i=0; i<MAX; i++){
            ans += dfs(i, 0, 1);
            ans %= MOD;
        }
        
        System.out.println(ans);
    }
}
0