結果
問題 | No.561 東京と京都 |
ユーザー |
![]() |
提出日時 | 2017-08-27 08:59:08 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 39 ms / 2,000 ms |
コード長 | 3,021 bytes |
コンパイル時間 | 2,260 ms |
コンパイル使用メモリ | 113,128 KB |
実行使用メモリ | 27,648 KB |
最終ジャッジ日時 | 2024-11-06 06:21:29 |
合計ジャッジ時間 | 2,834 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 17 |
コンパイルメッセージ
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.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("2 10000"); WillReturn.Add("20000 32000"); WillReturn.Add("24000 23000"); //45000 } else if (InputPattern == "Input2") { WillReturn.Add("2 10000"); WillReturn.Add("42000 50000"); WillReturn.Add("58000 56000"); //100000 } else if (InputPattern == "Input3") { WillReturn.Add("3 10"); WillReturn.Add("42000 50000"); WillReturn.Add("58000 56000"); WillReturn.Add("40000 45000"); //152970 } else if (InputPattern == "Input4") { WillReturn.Add("5 3000"); WillReturn.Add("10000 10000"); WillReturn.Add("20000 23000"); WillReturn.Add("30000 38000"); WillReturn.Add("44000 40000"); WillReturn.Add("54000 56000"); //164000 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } struct TKInfoDef { internal int T; internal int K; } static void Main() { List<string> InputList = GetInputList(); int[] wkArr = { }; Action<string> SplitAct = pStr => wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray(); SplitAct(InputList[0]); int D = wkArr[1]; var TKInfoList = new List<TKInfoDef>(); foreach (string EachStr in InputList.Skip(1)) { SplitAct(EachStr); TKInfoList.Add(new TKInfoDef() { T = wkArr[0], K = wkArr[1] }); } //収入合計[Is東京]なDP表 var PrevDP = new Dictionary<bool, int>(); PrevDP[true] = 0; foreach (TKInfoDef EachTKInfo in TKInfoList) { var CurrDP = new Dictionary<bool, int>(); Action<bool, int> UpdateAct = (pKey, pValue) => { if (CurrDP.ContainsKey(pKey) && CurrDP[pKey] >= pValue) return; CurrDP[pKey] = pValue; }; foreach (var EachPair in PrevDP) { //東京で働く場合 if (EachPair.Key) UpdateAct(true, EachPair.Value + EachTKInfo.T); else UpdateAct(true, EachPair.Value + EachTKInfo.T - D); //京都で働く場合 if (EachPair.Key) UpdateAct(false, EachPair.Value + EachTKInfo.K - D); else UpdateAct(false, EachPair.Value + EachTKInfo.K); } PrevDP = CurrDP; } Console.WriteLine(PrevDP.Values.Max()); } }