結果
問題 |
No.54 Happy Hallowe'en
|
ユーザー |
![]() |
提出日時 | 2016-06-13 05:00:40 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,094 bytes |
コンパイル時間 | 1,142 ms |
コンパイル使用メモリ | 111,728 KB |
実行使用メモリ | 56,516 KB |
最終ジャッジ日時 | 2024-10-09 13:07:22 |
合計ジャッジ時間 | 7,813 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 4 TLE * 1 -- * 14 |
コンパイルメッセージ
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 ieCount = int.Parse(Reader.ReadLine()); List<Ie> tempList = new List<Ie>(); int okashiTotal = 0; for(int i=0; i<ieCount; i++) { Ie ins = new Ie(i, Reader.ReadLine()); tempList.Add(ins); okashiTotal+=ins.Okashi; } tempList.Sort((a,b)=>{ if(a.Okashi + a.Sikii < b.Okashi + b.Sikii) { return -1; } else if(a.Okashi + a.Sikii > b.Okashi + b.Sikii) { return 1; } else if(a.Sikii < b.Sikii) { return -1; } else if(a.Sikii > b.Sikii) { return 1; } return 0; }); this.IeList = tempList.ToArray(); int ans = this.GetAns(0,0); Console.WriteLine(ans); } private Dictionary<int, Dictionary<int, int>> dic = new Dictionary<int, Dictionary<int, int>>(); private int GetAns(int idx, int hasOkashi) { if(!this.dic.ContainsKey(idx)) { this.dic.Add(idx, new Dictionary<int, int>()); } if(this.dic[idx].ContainsKey(hasOkashi)) { return this.dic[idx][hasOkashi]; } int ans = 0; if(idx >= this.IeList.Length) { return ans; } if(idx == this.IeList.Length - 1) { if(IeList[idx].Sikii > hasOkashi) { ans = IeList[idx].Okashi; } else { ans = 0; } } else { for(int i=idx; i<this.IeList.Length; i++) { if(this.IeList[i].Sikii <= hasOkashi) { continue; } int ret = this.GetAns(i+1, hasOkashi + this.IeList[i].Okashi) + this.IeList[i].Okashi; ans = Math.Max(ans, ret); } } dic[idx].Add(hasOkashi, ans); return ans; } private Ie[] IeList; public class Ie { public int Index; public int Okashi; public int Sikii; public Ie(int idx, string init) { int[] inpt = init.Split(' ').Select(a=>int.Parse(a)).ToArray(); this.Index = idx; this.Okashi = inpt[0]; this.Sikii = inpt[1]; } } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 2 1 3 100 2 "; 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(); } }