結果

問題 No.27 板の準備
ユーザー 14番14番
提出日時 2016-05-29 15:05:15
言語 C#(csc)
(csc 3.9.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 3,352 bytes
コンパイル時間 1,318 ms
コンパイル使用メモリ 108,928 KB
実行使用メモリ 24,960 KB
最終ジャッジ日時 2024-04-22 18:02:26
合計ジャッジ時間 2,603 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
19,840 KB
testcase_01 AC 29 ms
19,936 KB
testcase_02 AC 34 ms
21,108 KB
testcase_03 AC 31 ms
20,196 KB
testcase_04 AC 32 ms
20,828 KB
testcase_05 AC 35 ms
21,572 KB
testcase_06 AC 40 ms
22,484 KB
testcase_07 AC 37 ms
21,588 KB
testcase_08 AC 49 ms
24,960 KB
testcase_09 AC 40 ms
22,636 KB
testcase_10 AC 41 ms
22,644 KB
testcase_11 AC 37 ms
21,484 KB
testcase_12 AC 38 ms
22,384 KB
testcase_13 AC 32 ms
20,828 KB
testcase_14 AC 33 ms
21,200 KB
testcase_15 AC 39 ms
22,580 KB
testcase_16 AC 30 ms
20,348 KB
testcase_17 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 ans = int.MaxValue;
        int[] ita = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        for (int i = 1; i <= 30 - 2; i++)
        {
            for(int j=i+1; j<=30-1; j++) {
                for (int k = j + 1; k <= 30; k++)
                {
                    int cnt = 0;
                    bool cannot = false;
                    foreach (int num in ita)
                    {
                        int key = (1 << i) + (i << j) + (i << k);
                        int ret = this.GetAns(key, i, j, k, num);
                        if (ret == 0)
                        {
                            cannot = true;
                            break;
                        }
                        else
                        {
                            cnt += ret;
                        }
                    }
                    if (!cannot)
                    {
                        ans = Math.Min(cnt, ans);
                    }
                }
            }
        }
        Console.WriteLine(ans);
    }

    private Dictionary<int, Dictionary<int, int>> dic = new Dictionary<int, Dictionary<int, int>>();


    private int GetAns(int key, int a, int b, int c, int target)
    {
        if (!dic.ContainsKey(key))
        {
            dic.Add(key, new Dictionary<int, int>());
        }
        if (dic[key].ContainsKey(target))
        {
            return dic[key][target];
        }

        int ans = int.MaxValue;

        if (c == target)
        {
            ans = 1;
        }
        else if (target > c)
        {
            int ret = this.GetAns(key, a, b, c, target - c);
            if (ret > 0)
            {
                ret++;
                ans = Math.Min(ans, ret);
            }
        }

        if (b == target)
        {
            ans = 1;
        }
        else if (target > b)
        {
            int ret = this.GetAns(key, a, b, c, target - b);
            if (ret > 0)
            {
                ret++;
                ans = Math.Min(ans, ret);
            }
        }
        if (a == target)
        {
            ans = 1;

        }
        else if (target > a)
        {
            int ret = this.GetAns(key, a, b, c, target - a);
            if (ret > 0)
            {
                ret++;
                ans = Math.Min(ans, ret);
            }
        }
        if (ans == int.MaxValue)
        {
            ans = 0;
        }

        dic[key].Add(target, ans);
        return ans;
    }



    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


2 3 7 15





 
";
        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