結果
問題 |
No.37 遊園地のアトラクション
|
ユーザー |
![]() |
提出日時 | 2016-05-29 19:26:29 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,215 bytes |
コンパイル時間 | 867 ms |
コンパイル使用メモリ | 108,672 KB |
実行使用メモリ | 96,616 KB |
最終ジャッジ日時 | 2024-10-07 17:42:48 |
合計ジャッジ時間 | 13,751 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 4 |
other | AC * 2 TLE * 1 -- * 24 |
コンパイルメッセージ
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 maxTaizai = int.Parse(Reader.ReadLine()); int inputCount = int.Parse(Reader.ReadLine()); this.MachijikanList = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray(); int[] manzoku = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray(); int ans = this.GetAns(manzoku, maxTaizai); Console.WriteLine(ans); } private Dictionary<string, Dictionary<int, int>> dic = new Dictionary<string, Dictionary<int, int>>(); private int GetAns(int[] manzoku, int remain) { string key = string.Join("#", manzoku); if(!dic.ContainsKey(key)) { dic.Add(key, new Dictionary<int, int>()); } if(dic[key].ContainsKey(remain)) { return dic[key][remain]; } if(remain == 0) { return 0; } int ans = 0; for(int i=0; i<this.MachijikanList.Length; i++) { if(this.MachijikanList[i] <= remain) { int[] sub = (int[])manzoku.Clone(); sub[i] = sub[i] / 2; int ret = this.GetAns(sub, remain - this.MachijikanList[i]) + manzoku[i]; ans = Math.Max(ret, ans); } } dic[key].Add(remain, ans); return ans; } private int[] MachijikanList ; public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 9 2 8 2 9 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(); } }