結果
問題 | No.30 たこやき工場 |
ユーザー |
|
提出日時 | 2017-05-20 23:39:04 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 65 ms / 5,000 ms |
コード長 | 2,230 bytes |
コンパイル時間 | 1,124 ms |
コンパイル使用メモリ | 116,344 KB |
実行使用メモリ | 27,332 KB |
最終ジャッジ日時 | 2024-12-21 05:26:11 |
合計ジャッジ時間 | 2,303 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Collections.Generic; using System.IO; using System.Linq; public class Program { public static void Main() { Reader reader = new Reader(Console.In); int N = reader.RInt(); int M = reader.RInt(); var zairyo = new List<Zairyo>(); for (int i = 0; i < M; i++) { zairyo.Add(new Zairyo { moto = reader.RInt(), qty = reader.Int(), saki = reader.Int(), }); } var ans = new List<Ans>(); for (int i = 1; i <= N; i++) { ans.Add(new Ans { product = i, canBuy = !zairyo.Any(x => x.saki == i) }); } ans.FirstOrDefault(x => x.product == N).qty = 1; while (ans.Any(x => !x.canBuy && x.qty != 0)) { foreach (var item in ans.Where(x => !x.canBuy && x.qty != 0)) { foreach (var it in zairyo.Where(x => x.saki == item.product)) { ans.FirstOrDefault(x => x.product == it.moto).qty += it.qty * item.qty; } item.qty = 0; } } foreach(var item in ans.Where(x => x.product != N)) { Console.WriteLine(item.qty); } } } public class Ans { public int product; public bool canBuy; public long qty; } public class Zairyo { public int moto; public int qty; public int saki; } public class Reader { private readonly TextReader reader; private readonly char separator = ' '; private string[] A = new string[0]; private int i; public Reader(TextReader r) { reader = r; } public string String() { return Set(); } public int Int() { return int.Parse(Set()); } public long Long() { return long.Parse(Set()); } public string RString() { return RSet(); } public int RInt() { return int.Parse(RSet()); } public long RLong() { return long.Parse(RSet()); } public int[] IntArray() { return A.Select(x => int.Parse(x)).ToArray(); } private void Read() { string line = reader.ReadLine(); A = line.Split(separator); i = 0; } private string Set() { return A[i++]; } private string RSet() { Read(); return A[i++]; } }