結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー 14番14番
提出日時 2017-03-24 23:57:20
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 3,117 bytes
コンパイル時間 4,909 ms
コンパイル使用メモリ 108,424 KB
実行使用メモリ 81,832 KB
最終ジャッジ日時 2023-09-20 05:53:36
合計ジャッジ時間 9,089 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
26,172 KB
testcase_01 AC 71 ms
21,740 KB
testcase_02 AC 72 ms
21,768 KB
testcase_03 AC 72 ms
21,876 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
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<string, long>>> dic = new Dictionary<int, Dictionary<int, Dictionary<string, long>>>();

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

        string key = string.Join("#", remain);
        if (!dic.ContainsKey(x))
        {
            dic.Add(x, new Dictionary<int, Dictionary<string, long>>());
        }
        if (!dic[x].ContainsKey(y))
        {
            dic[x].Add(y, new Dictionary<string, 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