結果
問題 | No.496 ワープクリスタル (給料日前編) |
ユーザー | 14番 |
提出日時 | 2017-03-24 23:05:53 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 44 ms / 2,000 ms |
コード長 | 3,019 bytes |
コンパイル時間 | 1,024 ms |
コンパイル使用メモリ | 114,352 KB |
実行使用メモリ | 27,536 KB |
最終ジャッジ日時 | 2024-07-05 23:14:45 |
合計ジャッジ時間 | 2,882 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
コンパイルメッセージ
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.GoalX = inpt[0]; this.GoalY = inpt[1]; int crystalCount = inpt[2]; this.TohoCost = inpt[3]; for (int i = 0; i < crystalCount; i++) { inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); clist.Add(new Crystal(inpt[0], inpt[1], inpt[2])); } int ans = this.GetAns(0, 0, 0); Console.WriteLine(ans); } private Dictionary<int, Dictionary<int, Dictionary<int, int>>> dic = new Dictionary<int, Dictionary<int, Dictionary<int, int>>>(); private int GetAns(int idx, int x, int y) { if (x > GoalX || y > GoalY) { return -1; } if (idx >= clist.Count) { int tmp = (GoalX - x) + (GoalY - y); return tmp * TohoCost; } if (!dic.ContainsKey(idx)) { dic.Add(idx, new Dictionary<int, Dictionary<int, int>>()); } if (!dic[idx].ContainsKey(x)) { dic[idx].Add(x, new Dictionary<int, int>()); } if (dic[idx][x].ContainsKey(y)) { return dic[idx][x][y]; } int ans = -1; int ret = this.GetAns(idx + 1, x + clist[idx].MoveX, y + clist[idx].MoveY); if (ret >= 0) { ans = ret + clist[idx].Cost; } ret = this.GetAns(idx + 1, x, y); if (ret >= 0) { if (ans < 0) { ans = ret; } else { ans = Math.Min(ans, ret); } } dic[idx][x][y] = ans; return ans; } private int GoalX; private int GoalY; private int TohoCost; private List<Crystal> clist = new List<Crystal>(); private struct Crystal { public int MoveX; public int MoveY; public int Cost; public Crystal(int x, int y, int c) { this.MoveX = x; this.MoveY = y; this.Cost = c; } } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 5 3 5 2 5 0 6 5 0 6 2 2 6 0 2 3 3 1 6 "; 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(); } }