結果

問題 No.393 2本の竹
ユーザー 14番14番
提出日時 2016-07-16 20:28:37
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,797 bytes
コンパイル時間 3,049 ms
コンパイル使用メモリ 115,680 KB
実行使用メモリ 65,408 KB
最終ジャッジ日時 2024-04-23 13:51:48
合計ジャッジ時間 5,897 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
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 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 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();
    }
}
0