結果
| 問題 |
No.417 チューリップバブル
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-11-10 03:06:23 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,733 bytes |
| コンパイル時間 | 908 ms |
| コンパイル使用メモリ | 114,220 KB |
| 実行使用メモリ | 134,640 KB |
| 最終ジャッジ日時 | 2024-11-25 06:11:28 |
| 合計ジャッジ時間 | 80,210 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 WA * 4 TLE * 25 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;
public class Program
{
public void Proc() {
Reader.IsDebug = false;
int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
this.Map = new int[inpt[0]];
this.Tax = new long[inpt[0]];
this.TimeLimit = inpt[1];
for(int i=0; i<inpt[0]; i++) {
this.Tax[i] = long.Parse(Reader.ReadLine());
this.Map[i] = int.MaxValue;
}
for(int i=0; i<this.Map.Length-1; i++) {
inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
int[][] posList = new int[][]{new int[]{inpt[0], inpt[1]}, new int[]{inpt[1], inpt[0]}};
foreach(int[] pos in posList) {
if(!this.Road.ContainsKey(pos[0])) {
this.Road.Add(pos[0], new Dictionary<int, int>());
}
this.Road[pos[0]][pos[1]] = inpt[2];
}
}
this.Map[0] = 0;
Queue<int> que = new Queue<int>();
que.Enqueue(0);
while(que.Count > 0) {
int idx = que.Dequeue();
if(!Road.ContainsKey(idx)) {
continue;
}
foreach(int moveTo in Road[idx].Keys) {
int next = Map[idx] + this.Road[idx][moveTo];
if(Map[moveTo] > next) {
que.Enqueue(moveTo);
Map[moveTo] = next;
}
}
}
Console.WriteLine(Math.Max(Tax[0], GetAns(0, new int[this.Map.Length], this.TimeLimit)));
}
private Dictionary<int, Dictionary<int, Dictionary<string, long>>> dic = new Dictionary<int, Dictionary<int, Dictionary<string, long>>>();
private long GetAns(int pos, int[] flags, int remain) {
if(this.Map[pos] > remain) {
return -1;
}
if(pos == 0 && flags[0] == 1) {
return 0;
}
string key = string.Join(string.Empty, flags);
if(!dic.ContainsKey(pos)) {
dic.Add(pos, new Dictionary<int, Dictionary<string, long>>());
}
if(!dic[pos].ContainsKey(remain)) {
dic[pos].Add(remain, new Dictionary<string, long>());
}
if(dic[pos][remain].ContainsKey(key)) {
return dic[pos][remain][key];
}
long ans = -1;
long addTax = 0;
if(flags[pos] == 0) {
addTax = Tax[pos];
flags[pos] = 1;
}
foreach(int moveTo in this.Road[pos].Keys) {
long ret = this.GetAns(moveTo, flags, remain - this.Road[pos][moveTo]);
if(ret >= 0) {
ret+=addTax;
}
ans = Math.Max(ans, ret);
}
if(addTax > 0) {
flags[pos] = 0;
}
dic[pos][remain][key] = ans;
return ans;
}
private int TimeLimit;
private int[] Map;
private Dictionary<int, Dictionary<int, int>> Road = new Dictionary<int, Dictionary<int, int>>();
private long[] Tax;
public class Reader {
public static bool IsDebug = true;
private static System.IO.StringReader SReader;
private static string InitText = @"
2 50
10
50
0 1 50
";
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();
}
}
14番