結果

問題 No.30 たこやき工場
ユーザー fal_rndfal_rnd
提出日時 2016-11-27 14:09:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 198 ms / 5,000 ms
コード長 1,106 bytes
コンパイル時間 2,810 ms
コンパイル使用メモリ 76,356 KB
実行使用メモリ 58,768 KB
最終ジャッジ日時 2023-08-23 05:18:45
合計ジャッジ時間 5,848 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,360 KB
testcase_01 AC 121 ms
55,572 KB
testcase_02 AC 123 ms
55,584 KB
testcase_03 AC 129 ms
55,896 KB
testcase_04 AC 125 ms
55,632 KB
testcase_05 AC 125 ms
55,364 KB
testcase_06 AC 131 ms
55,580 KB
testcase_07 AC 129 ms
55,420 KB
testcase_08 AC 172 ms
56,120 KB
testcase_09 AC 180 ms
56,424 KB
testcase_10 AC 198 ms
58,768 KB
testcase_11 AC 152 ms
55,536 KB
testcase_12 AC 132 ms
55,444 KB
testcase_13 AC 137 ms
53,720 KB
testcase_14 AC 177 ms
58,440 KB
testcase_15 AC 178 ms
55,980 KB
testcase_16 AC 184 ms
58,412 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.util.Map.Entry;
class B{
	static Scanner s = new Scanner(System.in);
	public static void main(String[] args) {
		int size = Integer.parseInt(s.next());
		boolean[] buy = new boolean[size];
		Product[] p   = new Product[size];
		for(int i=0;i<size-1;++i) {
			p[i]=new Product();
		}
		p[size-1]=new PerfectP();
		Arrays.fill(buy, true);

		for(int i=Integer.parseInt(s.next());i>0;--i) {
			int from=Integer.parseInt(s.next())-1,
			    x   =Integer.parseInt(s.next()),
			    to  =Integer.parseInt(s.next())-1;
			buy[to]=false;
			p[from].needs.put(p[to], x);
		}
		for(int i=0;i<size;i++) {
			p[i].getNeeds();
		}
		for(int i=0;i<size-1;i++) {
			System.out.println((buy[i]?p[i].getNeeds():0));
		}
	}
}
class Product{
	HashMap<Product,Integer> needs = new HashMap<>();
	long memo=0;
	boolean explored=false;
	long getNeeds() {
		if(!explored) {
			explored=true;
			for(Entry<Product, Integer> e:needs.entrySet()) {
				memo+=e.getKey().getNeeds()*e.getValue();
			}
		}
		return memo;
	}
}
class PerfectP extends Product{
	@Override
	long getNeeds() {
		return 1;
	}
}
0