結果
| 問題 | No.30 たこやき工場 | 
| コンテスト | |
| ユーザー |  fal_rnd | 
| 提出日時 | 2016-11-27 14:09:23 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 197 ms / 5,000 ms | 
| コード長 | 1,106 bytes | 
| コンパイル時間 | 2,139 ms | 
| コンパイル使用メモリ | 80,016 KB | 
| 実行使用メモリ | 56,564 KB | 
| 最終ジャッジ日時 | 2024-12-21 05:26:04 | 
| 合計ジャッジ時間 | 5,568 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 17 | 
ソースコード
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;
	}
}
            
            
            
        