結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー 14番14番
提出日時 2017-03-25 00:13:34
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 3,213 bytes
コンパイル時間 4,645 ms
コンパイル使用メモリ 104,008 KB
実行使用メモリ 257,592 KB
最終ジャッジ日時 2023-09-20 07:00:10
合計ジャッジ時間 8,979 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
28,248 KB
testcase_01 AC 70 ms
19,884 KB
testcase_02 AC 69 ms
19,656 KB
testcase_03 AC 70 ms
23,820 KB
testcase_04 TLE -
testcase_05 AC 69 ms
20,012 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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];


        int[] crystalRemain = new int[crystalCount];
        this.CrystalList = new Crystal[crystalCount];

        for (int i = 0; i < crystalCount; i++)
        {
            inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            this.CrystalList[i] = new Crystal(inpt[0], inpt[1]);
            crystalRemain[i] = inpt[2];
        }
        long ans = GetAns(0, 0, crystalRemain);
        Console.WriteLine(ans);
    }

    private const long Mod = 1000000007;

    private Dictionary<int, Dictionary<int, Dictionary<long, long>>> dic = new Dictionary<int, Dictionary<int, Dictionary<long, long>>>();

    private long GetAns(int x, int y, int[] remain)
    {
        if (remain.Sum() == 0)
        {
            if (x == GoalX && y == GoalY)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }

        long key = 0;
        for (int i = 0; i < remain.Length; i++)
        {
            key = key * 100;
            key += remain[i];
        }

        if (!dic.ContainsKey(x))
        {
            dic.Add(x, new Dictionary<int, Dictionary<long, long>>());
        }
        if (!dic[x].ContainsKey(y))
        {
            dic[x].Add(y, new Dictionary<long, long>());

        }
        if (dic[x][y].ContainsKey(key))
        {
            return dic[x][y][key];
        }

        long ans = 0;
        if (x == GoalX && y == GoalY)
        {
            ans = 1;
        }
        for (int i = 0; i < CrystalList.Length; i++)
        {
            if (remain[i] <= 0)
            {
                continue;
            }
            remain[i]--;
            ans += GetAns(x + CrystalList[i].MoveX, y + CrystalList[i].MoveY, remain);
            ans = ans % Mod;
            remain[i]++;
        }
        dic[x][y][key] = ans;
        return ans;
    }

    private int GoalX = 0;
    private int GoalY = 0;

    private Crystal[] CrystalList;

    private class Crystal
    {
        public int MoveX;
        public int MoveY;
        public Crystal(int x, int y)
        {
            this.MoveX = x;
            this.MoveY = y;
        }
    }

    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"



1 0 3
-4 0 1
2 1 1
3 -1 1



";
        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