結果

問題 No.30 たこやき工場
ユーザー qazqaz
提出日時 2017-05-20 23:39:04
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 98 ms / 5,000 ms
コード長 2,230 bytes
コンパイル時間 2,817 ms
コンパイル使用メモリ 106,812 KB
実行使用メモリ 23,808 KB
最終ジャッジ日時 2023-08-23 05:18:54
合計ジャッジ時間 4,517 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
23,712 KB
testcase_01 AC 63 ms
21,808 KB
testcase_02 AC 65 ms
21,820 KB
testcase_03 AC 65 ms
21,728 KB
testcase_04 AC 64 ms
19,684 KB
testcase_05 AC 65 ms
21,820 KB
testcase_06 AC 65 ms
21,716 KB
testcase_07 AC 65 ms
21,796 KB
testcase_08 AC 67 ms
21,716 KB
testcase_09 AC 66 ms
21,628 KB
testcase_10 AC 98 ms
21,656 KB
testcase_11 AC 65 ms
21,656 KB
testcase_12 AC 64 ms
21,720 KB
testcase_13 AC 65 ms
23,808 KB
testcase_14 AC 66 ms
21,760 KB
testcase_15 AC 66 ms
21,732 KB
testcase_16 AC 66 ms
23,700 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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++]; }
}
0