結果
| 問題 |
No.498 ワープクリスタル (給料日編)
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2017-03-24 23:57:20 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,117 bytes |
| コンパイル時間 | 3,985 ms |
| コンパイル使用メモリ | 108,032 KB |
| 実行使用メモリ | 78,072 KB |
| 最終ジャッジ日時 | 2024-07-06 01:57:37 |
| 合計ジャッジ時間 | 5,764 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | TLE * 1 -- * 20 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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();
}
}
14番