結果
| 問題 |
No.393 2本の竹
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-07-16 20:28:37 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,797 bytes |
| コンパイル時間 | 1,024 ms |
| コンパイル使用メモリ | 109,312 KB |
| 実行使用メモリ | 65,152 KB |
| 最終ジャッジ日時 | 2024-10-15 13:53:45 |
| 合計ジャッジ時間 | 5,468 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 27 |
コンパイルメッセージ
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 dataSetCount = int.Parse(Reader.ReadLine());
for(int i=0; i<dataSetCount; i++) {
int[] takeList = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).OrderByDescending(a=>a).ToArray();
int kyakuCount = int.Parse(Reader.ReadLine());
KyakuList = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
this.dic = new Dictionary<int, Dictionary<int, Dictionary<long, int>>>();
Console.WriteLine(this.GetAns(takeList[0], takeList[1], 0));
}
}
private int[] KyakuList;
private Dictionary<int, Dictionary<int, Dictionary<long, int>>> dic = new Dictionary<int, Dictionary<int, Dictionary<long, int>>>();
private int GetAns(int takeLong, int takeShort, long flag) {
if(flag == (1<<KyakuList.Length) - 1) {
return 0;
}
if(!this.dic.ContainsKey(takeLong)) {
this.dic.Add(takeLong, new Dictionary<int, Dictionary<long,int>>());
}
if(!this.dic[takeLong].ContainsKey(takeShort)) {
this.dic[takeLong].Add(takeShort, new Dictionary<long, int>());
}
if(this.dic[takeLong][takeShort].ContainsKey(flag)) {
return this.dic[takeLong][takeShort][flag];
}
int ans = 0;
for(int i=0; i<KyakuList.Length; i++) {
int key = (1<<i);
if((flag & key) != 0) {
continue;
}
if(KyakuList[i] <= takeShort) {
ans = Math.Max(ans, this.GetAns(takeLong, takeShort - this.KyakuList[i], flag + key) + 1);
}
if(KyakuList[i] <= takeLong) {
int takeTemp = takeLong - KyakuList[i];
ans = Math.Max(ans, this.GetAns(Math.Max(takeTemp, takeShort), Math.Min(takeTemp, takeShort), flag + key) + 1);
}
}
this.dic[takeLong][takeShort].Add(flag, ans);
return ans;
}
public class Reader
{
public static bool IsDebug = true;
private static String PlainInput = @"
2
10 14
5
4 3 2 7 8
10 10
3
7 7 5
";
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番