結果
問題 | No.417 チューリップバブル |
ユーザー | 14番 |
提出日時 | 2016-09-03 14:11:24 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,867 bytes |
コンパイル時間 | 3,414 ms |
コンパイル使用メモリ | 116,080 KB |
実行使用メモリ | 119,464 KB |
最終ジャッジ日時 | 2024-11-15 18:35:37 |
合計ジャッジ時間 | 90,464 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
34,376 KB |
testcase_01 | AC | 41 ms
119,464 KB |
testcase_02 | AC | 42 ms
32,696 KB |
testcase_03 | AC | 42 ms
115,136 KB |
testcase_04 | AC | 43 ms
32,300 KB |
testcase_05 | AC | 40 ms
103,608 KB |
testcase_06 | AC | 43 ms
32,540 KB |
testcase_07 | AC | 42 ms
79,396 KB |
testcase_08 | TLE | - |
testcase_09 | TLE | - |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | TLE | - |
testcase_24 | AC | 40 ms
32,316 KB |
testcase_25 | TLE | - |
testcase_26 | TLE | - |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | TLE | - |
testcase_32 | AC | 39 ms
30,552 KB |
testcase_33 | AC | 42 ms
96,684 KB |
testcase_34 | TLE | - |
testcase_35 | TLE | - |
testcase_36 | TLE | - |
testcase_37 | TLE | - |
testcase_38 | TLE | - |
testcase_39 | TLE | - |
コンパイルメッセージ
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.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); this.MuraCount = inpt[0]; this.TimeLimit = inpt[1]; this.Zeisyu = new long[this.MuraCount + 1]; for (int i = 0; i < MuraCount; i++) { this.Zeisyu[i] = long.Parse(Reader.ReadLine()); } for (int i = 0; i < MuraCount - 1; i++) { inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray(); int m1 = inpt[0]; int m2 = inpt[1]; int cost = inpt[2]; if (!this.Road.ContainsKey(m1)) { this.Road.Add(m1, new Dictionary<int, int>()); } this.Road[m1][m2] = cost; if(!this.Road.ContainsKey(m2)) { this.Road.Add(m2, new Dictionary<int,int>()); } this.Road[m2][m1] = cost; } bool[] flags = new bool[MuraCount]; flags[0] = true; long ans = Zeisyu[0]; ans = Math.Max(ans, this.GetAns(0, TimeLimit, flags) + Zeisyu[0]); Console.WriteLine(ans); } private Dictionary<int, Dictionary<int, Dictionary<string, long>>> dic = new Dictionary<int, Dictionary<int, Dictionary<string, long>>>(); private long GetAns(int pos, int remainTime, bool[] flags) { string key = string.Join(string.Empty, flags.Select(a => a ? 1 : 0)); if (!dic.ContainsKey(pos)) { dic.Add(pos, new Dictionary<int, Dictionary<string, long>>()); } if (!dic[pos].ContainsKey(remainTime)) { dic[pos].Add(remainTime, new Dictionary<string, long>()); } if (dic[pos][remainTime].ContainsKey(key)) { return dic[pos][remainTime][key]; } if (remainTime < 0) { return -1; } if (remainTime == 0) { if (pos == 0) { return 0; } else { return -1; } } long ans = -1; if (pos == 0) { ans = 0; } if (dic.ContainsKey(pos)) { bool canGetTax = !flags[pos]; flags[pos] = true; foreach (int nextPos in Road[pos].Keys) { long ret = this.GetAns(nextPos, remainTime - Road[pos][nextPos], flags); if (ret >= 0) { if (canGetTax) { ret += Zeisyu[pos]; } ans = Math.Max(ans, ret); } } if (canGetTax) { flags[pos] = false; } } dic[pos][remainTime].Add(key, ans); return ans; } private Dictionary<int, Dictionary<int, int>> Road = new Dictionary<int, Dictionary<int, int>>(); private int MuraCount; private int TimeLimit; long[] Zeisyu; public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 2 50 10 50 0 1 50 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }