結果

問題 No.107 モンスター
ユーザー 14番14番
提出日時 2016-04-14 20:33:53
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 2,041 ms / 5,000 ms
コード長 2,805 bytes
コンパイル時間 3,908 ms
コンパイル使用メモリ 107,392 KB
実行使用メモリ 70,844 KB
最終ジャッジ日時 2023-08-23 06:53:59
合計ジャッジ時間 14,705 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
20,928 KB
testcase_01 AC 63 ms
22,724 KB
testcase_02 AC 63 ms
22,816 KB
testcase_03 AC 62 ms
20,804 KB
testcase_04 AC 60 ms
20,728 KB
testcase_05 AC 61 ms
20,768 KB
testcase_06 AC 61 ms
20,612 KB
testcase_07 AC 59 ms
20,652 KB
testcase_08 AC 61 ms
20,856 KB
testcase_09 AC 61 ms
20,848 KB
testcase_10 AC 62 ms
20,884 KB
testcase_11 AC 60 ms
18,716 KB
testcase_12 AC 61 ms
22,716 KB
testcase_13 AC 130 ms
27,448 KB
testcase_14 AC 365 ms
36,580 KB
testcase_15 AC 363 ms
34,652 KB
testcase_16 AC 63 ms
20,768 KB
testcase_17 AC 134 ms
29,444 KB
testcase_18 AC 75 ms
25,016 KB
testcase_19 AC 80 ms
24,980 KB
testcase_20 AC 1,876 ms
52,392 KB
testcase_21 AC 909 ms
51,272 KB
testcase_22 AC 2,041 ms
70,844 KB
testcase_23 AC 1,637 ms
60,400 KB
testcase_24 AC 1,103 ms
60,628 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 monsterCount = int.Parse(Reader.ReadLine());

        this.MonsterList = Reader.GetInt();


        int ans = this.GetAns(100, 100, Convert.ToInt32("1".PadLeft(monsterCount, '1'), 2));
        Console.WriteLine(ans);

    }

    private int[] MonsterList;

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

    private int GetAns(int hp, int maxHp, int target)
    {
        if (!dic.ContainsKey(hp))
        {
            dic.Add(hp, new Dictionary<int,int>());
        }
        if (dic[hp].ContainsKey(target))
        {
            return dic[hp][target];
        }

        int ans = 0;

        if (target == 0)
        {
            ans = hp;
        } else if(hp <= 0) {
            ans = 0;
        }
        else
        {
            for (int i = 0; i < MonsterList.Length; i++)
            {
                int key = Convert.ToInt32("1".PadRight(i + 1, '0'), 2);
                if ((target & key) == key)
                {
                    int nextHP = Math.Min(maxHp, hp + this.MonsterList[i]);
                    int nextMaxHp = maxHp;
                    if (this.MonsterList[i] < 0)
                    {
                        nextMaxHp += 100;
                    }
                    int ret = this.GetAns(nextHP, nextMaxHp, target - key);
                    ans = Math.Max(ans, ret);
                }
            }
        }

        this.dic[hp].Add(target, ans);
        return ans;

    }



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



4
-40 -60 210 -110



 
";
        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();
            }
        }
        public static int[] GetInt(char delimiter = ' ', bool trim = false)
        {
            string inptStr = ReadLine();
            if (trim)
            {
                inptStr = inptStr.Trim();
            }
            string[] inpt = inptStr.Split(delimiter);
            int[] ret = new int[inpt.Length];
            for (int i = 0; i < inpt.Length; i++)
            {
                ret[i] = int.Parse(inpt[i]);
            }
            return ret;
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0