結果

問題 No.30 たこやき工場
ユーザー Daigo HIROOKADaigo HIROOKA
提出日時 2018-07-01 03:31:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 211 ms / 5,000 ms
コード長 896 bytes
コンパイル時間 4,153 ms
コンパイル使用メモリ 74,360 KB
実行使用メモリ 58,796 KB
最終ジャッジ日時 2023-08-23 05:20:48
合計ジャッジ時間 7,466 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,748 KB
testcase_01 AC 123 ms
56,300 KB
testcase_02 AC 126 ms
56,028 KB
testcase_03 AC 128 ms
55,756 KB
testcase_04 AC 127 ms
55,820 KB
testcase_05 AC 126 ms
55,692 KB
testcase_06 AC 131 ms
55,820 KB
testcase_07 AC 131 ms
55,528 KB
testcase_08 AC 175 ms
55,964 KB
testcase_09 AC 181 ms
56,192 KB
testcase_10 AC 211 ms
58,796 KB
testcase_11 AC 176 ms
56,264 KB
testcase_12 AC 133 ms
55,464 KB
testcase_13 AC 143 ms
55,528 KB
testcase_14 AC 184 ms
56,012 KB
testcase_15 AC 185 ms
56,276 KB
testcase_16 AC 193 ms
56,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class No030{
	static int[] dp;
	static int[][] in;
	
	static int dfs(int i, int n){
		if(i == n) return 1;
		if(dp[i] != 0) return dp[i];
		int res = 0;
		for(int j = 1; j < 101; j++){
			if(in[i][j] != 0){
				res += in[i][j]*dfs(j, n);
			}
		}
		return dp[i] = res;
	}
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		dp = new int[101];
		int[] ans = new int[101];
		Arrays.fill(ans, -1);
		in = new int[101][101];
		for(int i = 0; i < m; i++){
			int p = sc.nextInt();
			int q = sc.nextInt();
			int r = sc.nextInt();
			in[p][r] = q;
		}

		for(int i = 1; i < n; i++){
			boolean flg = true;
			for(int j = 1; j < 101; j++){
				if(in[j][i] != 0){
					System.out.println(0);
					flg = false;
					break;
				}
			}
			if(flg){
				System.out.println(dfs(i, n));
			}
		}
	}
}
0