結果
| 問題 |
No.107 モンスター
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-04-14 20:33:53 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 2,079 ms / 5,000 ms |
| コード長 | 2,805 bytes |
| コンパイル時間 | 2,906 ms |
| コンパイル使用メモリ | 105,984 KB |
| 実行使用メモリ | 67,636 KB |
| 最終ジャッジ日時 | 2024-12-21 07:21:09 |
| 合計ジャッジ時間 | 12,644 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
コンパイルメッセージ
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 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();
}
}
14番