結果

問題 No.30 たこやき工場
ユーザー nanophoto12nanophoto12
提出日時 2014-11-02 22:30:39
言語 C#(csc)
(csc 3.9.0)
結果
MLE  
実行時間 -
コード長 2,231 bytes
コンパイル時間 2,279 ms
コンパイル使用メモリ 109,492 KB
実行使用メモリ 822,904 KB
最終ジャッジ日時 2023-08-29 00:21:42
合計ジャッジ時間 6,939 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
23,780 KB
testcase_01 AC 60 ms
19,716 KB
testcase_02 AC 62 ms
23,900 KB
testcase_03 AC 61 ms
23,776 KB
testcase_04 AC 60 ms
21,664 KB
testcase_05 AC 61 ms
23,812 KB
testcase_06 AC 60 ms
21,772 KB
testcase_07 AC 60 ms
21,592 KB
testcase_08 AC 117 ms
46,292 KB
testcase_09 AC 62 ms
21,768 KB
testcase_10 MLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Linq;

public class Program
{
    private class Source
    {
        private readonly int _id;
        private readonly uint _count;

        public Source(int id, uint count)
        {
            _id = id;
            _count = count;
        }

        public int Id
        {
            get { return _id; }
        }

        public uint Count
        {
            get { return _count; }
        }

        public Source Mul(uint count)
        {
            return new Source(_id, _count * count);
        }
    }

    private static List<Source> Dfs(List<Source>[] sourceList, List<Source>[] memo, int id, bool[] used)
    {
        if (sourceList[id].Count == 0)
        {
            return new List<Source>{ new Source(id, 1)};
        }
        if (!used[id])
        {
            var sources = new List<Source>();
            foreach (var source in sourceList[id])
            {
                var result = Dfs(sourceList, memo, source.Id, used);
                foreach (var element in result)
                {
                    sources.Add(element.Mul(source.Count));
                }
            }
            used[id] = true;
            memo[id] = sources;
        }
        return memo[id];
    }

    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int m = int.Parse(Console.ReadLine());
        List<Source>[] list = new List<Source>[n + 1];
        for (int i = 0; i < n + 1; i++)
        {
            list[i] = new List<Source>();
        }
        for (int i = 0; i < m; i++)
        {
            var line = Console.ReadLine().Split(' ').Select(element => int.Parse(element)).ToArray();
            list[line[2]].Add(new Source(line[0], (uint)line[1]));
        }
        bool[] used = new bool[n + 1];
        var result = Dfs(list, new List<Source>[n+1],  n, used);
        uint[] count = new uint[n+1];
        foreach (var element in result)
        {
            count[element.Id] += element.Count;
        }
        for (int i = 1; i < n; i++)
        {
            Console.WriteLine(count[i]);
        }
    }
}
0