結果
| 問題 |
No.393 2本の竹
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-07-16 20:39:15 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,097 bytes |
| コンパイル時間 | 960 ms |
| コンパイル使用メモリ | 112,256 KB |
| 実行使用メモリ | 55,320 KB |
| 最終ジャッジ日時 | 2024-10-15 13:54:57 |
| 合計ジャッジ時間 | 5,363 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / 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)).OrderBy(a=>a).ToArray();
Console.WriteLine(this.GetAns(takeList[0], takeList[1], 0));
}
}
private int[] KyakuList;
private Dictionary<int, Dictionary<int, Dictionary<string, int>>> dic = new Dictionary<int, Dictionary<int, Dictionary<string, int>>>();
private String GetKey(long flag) {
StringBuilder key = new StringBuilder();
for(int i=0; i<KyakuList.Length; i++) {
long k= (i<<i);
if((flag & k) > 0) {
key.Append("#" + KyakuList[i]);
}
}
return key.ToString();
}
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<string,int>>());
}
if(!this.dic[takeLong].ContainsKey(takeShort)) {
this.dic[takeLong].Add(takeShort, new Dictionary<string, int>());
}
string key = this.GetKey(flag);
if(this.dic[takeLong][takeShort].ContainsKey(key)) {
return this.dic[takeLong][takeShort][key];
}
int ans = 0;
for(int i=0; i<KyakuList.Length; i++) {
long tempFlag = (1<<i);
if((flag & tempFlag) != 0) {
continue;
}
if(KyakuList[i] <= takeShort) {
ans = Math.Max(ans, this.GetAns(takeLong, takeShort - this.KyakuList[i], flag + tempFlag) + 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 + tempFlag) + 1);
}
}
this.dic[takeLong][takeShort].Add(key, 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番