結果
問題 | No.561 東京と京都 |
ユーザー |
![]() |
提出日時 | 2024-10-10 23:06:20 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 41 ms / 2,000 ms |
コード長 | 4,047 bytes |
コンパイル時間 | 1,080 ms |
コンパイル使用メモリ | 114,908 KB |
実行使用メモリ | 19,584 KB |
最終ジャッジ日時 | 2024-10-10 23:06:23 |
合計ジャッジ時間 | 3,019 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 //A君は2日間だけ仕事をします。 //東京と京都の移動には10000円かかります。 //1日目は東京の仕事で20000円もらえ、京都の仕事で32000円もらえます。 //2日目は東京の仕事で24000円もらえ、京都の仕事で23000円もらえます。 // //A君は1日目に京都へ10000円で移動して仕事をすると22000円増やすことができます。 //2日目はそのまま京都で仕事をすることで23000円増やすことができます。 // //A君は京都に移動したのち2日間とも京都で働いて45000円増やすことができました。 } else if (InputPattern == "Input2") { WillReturn.Add("2 10000"); WillReturn.Add("42000 50000"); WillReturn.Add("58000 56000"); //100000 //この場合A君は移動せず2日間とも東京で働いて //100000円増やすことができます。 } else if (InputPattern == "Input3") { WillReturn.Add("3 10"); WillReturn.Add("42000 50000"); WillReturn.Add("58000 56000"); WillReturn.Add("40000 45000"); //152970 //移動のコストが10円と格安です。 //A君は京都、東京、京都の順で仕事を選んで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()); } }