結果

問題 No.30 たこやき工場
ユーザー Daigo HIROOKADaigo HIROOKA
提出日時 2018-07-01 03:01:56
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,059 bytes
コンパイル時間 3,179 ms
コンパイル使用メモリ 75,104 KB
実行使用メモリ 49,380 KB
最終ジャッジ日時 2023-09-13 16:28:28
合計ジャッジ時間 12,647 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
44,356 KB
testcase_01 AC 124 ms
39,704 KB
testcase_02 AC 128 ms
39,520 KB
testcase_03 AC 126 ms
40,160 KB
testcase_04 AC 125 ms
39,292 KB
testcase_05 AC 125 ms
39,308 KB
testcase_06 AC 129 ms
39,432 KB
testcase_07 AC 129 ms
39,584 KB
testcase_08 AC 281 ms
49,380 KB
testcase_09 AC 183 ms
40,468 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);
		LinkedList<Integer> link = new LinkedList<Integer>();
		for(int i = 0; i < n-1; i++){
			ans[i] = list[n-1][i];
			if(list[n-1][i] > 0){
				link.offer(i);
			}
		}

		while(link.size() > 0){
			int idx = link.poll();
			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.offer(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