結果

問題 No.498 ワープクリスタル (給料日編)
ユーザー 14番14番
提出日時 2017-03-25 00:15:48
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,096 ms / 2,000 ms
コード長 2,889 bytes
コンパイル時間 3,559 ms
コンパイル使用メモリ 108,968 KB
実行使用メモリ 69,448 KB
最終ジャッジ日時 2023-09-20 07:11:36
合計ジャッジ時間 18,400 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
19,876 KB
testcase_01 AC 65 ms
21,948 KB
testcase_02 AC 67 ms
24,060 KB
testcase_03 AC 66 ms
21,880 KB
testcase_04 AC 1,086 ms
67,180 KB
testcase_05 AC 66 ms
19,816 KB
testcase_06 AC 1,073 ms
67,884 KB
testcase_07 AC 1,039 ms
69,448 KB
testcase_08 AC 1,030 ms
69,176 KB
testcase_09 AC 1,096 ms
68,220 KB
testcase_10 AC 66 ms
24,008 KB
testcase_11 AC 192 ms
35,412 KB
testcase_12 AC 66 ms
23,936 KB
testcase_13 AC 95 ms
29,592 KB
testcase_14 AC 68 ms
23,984 KB
testcase_15 AC 69 ms
21,960 KB
testcase_16 AC 68 ms
21,984 KB
testcase_17 AC 68 ms
21,784 KB
testcase_18 AC 1,081 ms
67,192 KB
testcase_19 AC 1,068 ms
67,204 KB
testcase_20 AC 1,095 ms
67,888 KB
testcase_21 AC 1,084 ms
68,848 KB
testcase_22 AC 1,075 ms
67,800 KB
testcase_23 AC 1,070 ms
67,788 KB
testcase_24 AC 1,080 ms
67,184 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];


        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<long, long> dic = new 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(key))
        {
            return dic[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[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