結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー 14番14番
提出日時 2017-03-24 23:01:35
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,871 bytes
コンパイル時間 2,654 ms
コンパイル使用メモリ 110,988 KB
実行使用メモリ 26,032 KB
最終ジャッジ日時 2023-09-20 02:45:46
合計ジャッジ時間 5,916 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
23,952 KB
testcase_01 AC 68 ms
21,860 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 68 ms
21,948 KB
testcase_06 AC 62 ms
21,912 KB
testcase_07 AC 62 ms
21,968 KB
testcase_08 AC 73 ms
21,968 KB
testcase_09 AC 73 ms
21,916 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.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 = 0;
        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)
        {
            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 = @"

3 3 2 1
1 2 2
2 1 4




";
        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();
    }
}
0