結果

問題 No.468 役に立つ競技プログラミング実践編
ユーザー 14番14番
提出日時 2016-12-18 10:21:06
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 975 ms / 2,000 ms
コード長 3,457 bytes
コンパイル時間 2,891 ms
コンパイル使用メモリ 109,120 KB
実行使用メモリ 95,568 KB
最終ジャッジ日時 2023-08-21 00:37:51
合計ジャッジ時間 16,811 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
21,972 KB
testcase_01 AC 74 ms
24,084 KB
testcase_02 AC 74 ms
22,124 KB
testcase_03 AC 75 ms
22,076 KB
testcase_04 AC 76 ms
21,980 KB
testcase_05 AC 76 ms
19,876 KB
testcase_06 AC 76 ms
21,932 KB
testcase_07 AC 77 ms
23,984 KB
testcase_08 AC 77 ms
23,988 KB
testcase_09 AC 76 ms
22,064 KB
testcase_10 AC 76 ms
22,012 KB
testcase_11 AC 75 ms
22,008 KB
testcase_12 AC 76 ms
23,996 KB
testcase_13 AC 75 ms
22,004 KB
testcase_14 AC 82 ms
26,032 KB
testcase_15 AC 82 ms
24,068 KB
testcase_16 AC 82 ms
24,024 KB
testcase_17 AC 82 ms
24,104 KB
testcase_18 AC 82 ms
23,988 KB
testcase_19 AC 83 ms
24,100 KB
testcase_20 AC 83 ms
24,116 KB
testcase_21 AC 82 ms
26,012 KB
testcase_22 AC 82 ms
24,044 KB
testcase_23 AC 84 ms
23,984 KB
testcase_24 AC 958 ms
94,864 KB
testcase_25 AC 959 ms
92,880 KB
testcase_26 AC 975 ms
93,880 KB
testcase_27 AC 963 ms
91,816 KB
testcase_28 AC 966 ms
93,832 KB
testcase_29 AC 962 ms
89,804 KB
testcase_30 AC 972 ms
95,568 KB
testcase_31 AC 960 ms
93,776 KB
testcase_32 AC 965 ms
94,876 KB
testcase_33 AC 967 ms
91,816 KB
testcase_34 AC 420 ms
85,532 KB
testcase_35 AC 78 ms
23,972 KB
testcase_36 AC 75 ms
21,964 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.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{
    public void Proc() {
        Reader.IsDebug = false;
        int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();

        this.MemberCount = inpt[0];
        this.PathCount = inpt[1];
        this.maxCost = new long[this.MemberCount].Select(a=>(long)-1).ToArray();
        this.minCost.Add(0,0);

        for(int i=0; i<this.PathCount; i++) {
            inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
            if(!this.PathDic.ContainsKey(inpt[0])) {
                this.PathDic.Add(inpt[0], new Dictionary<int, int>());
            }
            this.PathDic[inpt[0]].Add(inpt[1], inpt[2]);

            if(!this.PathRev.ContainsKey(inpt[1])) {
                this.PathRev.Add(inpt[1], new Dictionary<int, int>());
            }
            this.PathRev[inpt[1]].Add(inpt[0], inpt[2]);
        }

        Queue<int> que = new Queue<int>();
        PathDic[0].Keys.ToList().ForEach(a=>que.Enqueue(a));
        while(que.Count > 0) {
            int cur = que.Dequeue();
            if(minCost.ContainsKey(cur)) {
                continue;
            }
            if(PathRev[cur].Any(a=>!minCost.ContainsKey(a.Key))) {
                continue;
            }
            minCost[cur] = PathRev[cur].Max(a=>minCost[a.Key] + a.Value);
            if(cur == this.MemberCount - 1) {
                continue;
            }
            PathDic[cur].ToList().ForEach(a=>que.Enqueue(a.Key));
        }



        maxCost[this.MemberCount-1] = minCost[this.MemberCount-1];
        que.Clear();
        PathRev[this.MemberCount-1].ToList().ForEach(a=>{
            que.Enqueue(a.Key);
        });
        while(que.Count > 0) {
            int cur = que.Dequeue();
            if(maxCost[cur] >= 0) {
                continue;
            }
            if(PathDic[cur].Any(a=>maxCost[a.Key] < 0)) {
                continue;
            }
            maxCost[cur] = PathDic[cur].Min(a=>maxCost[a.Key] - a.Value);
            if(cur == 0) {
                continue;
            }
            PathRev[cur].ToList().ForEach(a=>que.Enqueue(a.Key));
        }
        string ans = minCost[this.MemberCount-1] + " " + minCost.Count(a=>a.Value != maxCost[a.Key]) + "/" + this.MemberCount;
        Console.WriteLine(ans);

    }

    private Dictionary<int, Dictionary<int, int>> PathDic = new Dictionary<int, Dictionary<int, int>>();
    private Dictionary<int, Dictionary<int, int>> PathRev = new Dictionary<int, Dictionary<int, int>>();

    private Dictionary<int, long> minCost = new Dictionary<int, long>();
    private long[] maxCost;

    private int MemberCount;
    private int PathCount;

    public class Reader {
        public static bool IsDebug = true;
        private static System.IO.StringReader SReader;
        private static string InitText = @"



8 12
0 1 3
0 2 3
1 3 3
1 4 3
2 3 3
2 4 3
3 5 3
3 6 3
4 5 3
4 6 3
5 7 3
6 7 3


";
        public static string ReadLine() {
            if(IsDebug) {
                if(SReader == null) {
                    SReader = new System.IO.StringReader(InitText.Trim());
                }
                return SReader.ReadLine();
            } else {
                return Console.ReadLine();
            }
        }
    }
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0