結果

問題 No.30 たこやき工場
ユーザー Daigo HIROOKADaigo HIROOKA
提出日時 2018-07-01 03:14:43
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,096 bytes
コンパイル時間 3,229 ms
コンパイル使用メモリ 75,516 KB
実行使用メモリ 57,100 KB
最終ジャッジ日時 2023-09-13 16:29:27
合計ジャッジ時間 12,497 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
56,060 KB
testcase_01 AC 122 ms
56,096 KB
testcase_02 AC 124 ms
55,680 KB
testcase_03 AC 126 ms
55,724 KB
testcase_04 AC 127 ms
56,072 KB
testcase_05 AC 125 ms
55,528 KB
testcase_06 AC 132 ms
55,992 KB
testcase_07 AC 129 ms
55,964 KB
testcase_08 AC 271 ms
57,100 KB
testcase_09 AC 186 ms
56,292 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class No030{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		int[][] list = new int[n][n];
		for(int i = 0; i < n; i++){
			Arrays.fill(list[i], 0);
		}
		for(int i = 0; i < m; i++){
			int p = sc.nextInt()-1;
			int q = sc.nextInt();
			int r = sc.nextInt()-1;
			list[r][p] = q;
		}
		// System.out.println(Arrays.deepToString(list));
		long[] ans = new long[n-1];
		Arrays.fill(ans, 0);
		ArrayList<Integer> link = new ArrayList<Integer>();
		for(int i = 0; i < n-1; i++){
			ans[i] = list[n-1][i];
			if(list[n-1][i] > 0){
				link.add(i);
			}
		}

		while(link.size() > 0){
			int idx = link.get(link.size()-1);
			link.remove(link.size()-1);
			boolean start = true;
			long num = ans[idx];
			for(int i = 0; i < n-1; i++){
				ans[i] += num*list[idx][i];
				if(list[idx][i] > 0){
					link.add(i);
					start = false;
				}
			}
			if(!start){
				ans[idx] = 0;
			}
			// System.out.println(link);
		}
		for(int i = 0; i < n-1; i++){
			System.out.println(ans[i]);
		}
	}
}
0