結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー 14番14番
提出日時 2017-03-24 23:05:53
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 3,019 bytes
コンパイル時間 2,542 ms
コンパイル使用メモリ 106,880 KB
実行使用メモリ 24,052 KB
最終ジャッジ日時 2023-09-20 02:54:26
合計ジャッジ時間 5,502 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
21,800 KB
testcase_01 AC 66 ms
21,932 KB
testcase_02 AC 70 ms
23,984 KB
testcase_03 AC 68 ms
21,868 KB
testcase_04 AC 67 ms
21,956 KB
testcase_05 AC 68 ms
21,904 KB
testcase_06 AC 62 ms
19,820 KB
testcase_07 AC 61 ms
23,920 KB
testcase_08 AC 72 ms
21,952 KB
testcase_09 AC 72 ms
22,036 KB
testcase_10 AC 70 ms
21,952 KB
testcase_11 AC 69 ms
23,932 KB
testcase_12 AC 69 ms
19,796 KB
testcase_13 AC 72 ms
21,896 KB
testcase_14 AC 72 ms
22,084 KB
testcase_15 AC 72 ms
21,952 KB
testcase_16 AC 70 ms
21,956 KB
testcase_17 AC 69 ms
23,824 KB
testcase_18 AC 69 ms
24,052 KB
testcase_19 AC 69 ms
23,864 KB
testcase_20 AC 69 ms
23,856 KB
testcase_21 AC 68 ms
21,816 KB
testcase_22 AC 73 ms
21,816 KB
testcase_23 AC 78 ms
24,032 KB
testcase_24 AC 73 ms
21,936 KB
testcase_25 AC 71 ms
23,800 KB
testcase_26 AC 73 ms
21,816 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.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();
    }
}
0