結果
問題 |
No.37 遊園地のアトラクション
|
ユーザー |
![]() |
提出日時 | 2015-07-21 19:26:03 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,693 bytes |
コンパイル時間 | 999 ms |
コンパイル使用メモリ | 107,904 KB |
実行使用メモリ | 19,456 KB |
最終ジャッジ日時 | 2024-07-08 11:33:46 |
合計ジャッジ時間 | 3,023 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 3 |
other | WA * 27 |
コンパイルメッセージ
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 = "Input4"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("5"); WillReturn.Add("3"); WillReturn.Add("1 2 3"); WillReturn.Add("3 2 1"); } else if (InputPattern == "Input2") { WillReturn.Add("9"); WillReturn.Add("2"); WillReturn.Add("8 2"); WillReturn.Add("9 7"); } else if (InputPattern == "Input3") { WillReturn.Add("9"); WillReturn.Add("2"); WillReturn.Add("8 2"); WillReturn.Add("9 5"); } else if (InputPattern == "Input4") { WillReturn.Add("20"); WillReturn.Add("5"); WillReturn.Add("10 7 9 5 7"); WillReturn.Add("5 8 2 8 1"); } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } struct JyoutaiDef { internal int CurrP; internal int CSum; internal int VSum; internal int[] CurrVArr; internal string Path; } static void Main() { List<string> InputList = GetInputList(); int T = int.Parse(InputList[0]); int[] CArr = InputList[2].Split(' ').Select(X => int.Parse(X)).ToArray(); int[] VArr = InputList[3].Split(' ').Select(X => int.Parse(X)).ToArray(); int UB = CArr.GetUpperBound(0); var stk = new Stack<JyoutaiDef>(); JyoutaiDef WillPush; WillPush.CurrP = 0; WillPush.CSum = 0; WillPush.VSum = 0; WillPush.CurrVArr = VArr; WillPush.Path = ""; stk.Push(WillPush); int AnswerVSum = 0; string AnswerPath = ""; while (stk.Count > 0) { JyoutaiDef Popped = stk.Pop(); //Console.WriteLine("満足度合計={0}", Popped.VSum); //Console.WriteLine(Popped.Path); //解の更新 if (AnswerVSum < Popped.VSum) { AnswerVSum = Popped.VSum; AnswerPath = Popped.Path; } for (int I = Popped.CurrP; I <= UB; I++) { //対象アトラクションの満足度が0ならContinue; int CurrV = Popped.CurrVArr[I]; if (CurrV == 0) continue; //Push処理 WillPush.CurrP = I; WillPush.CSum = Popped.CSum + CArr[I]; if (WillPush.CSum > T) continue; WillPush.VSum = Popped.VSum + CurrV; WillPush.CurrVArr = (int[])Popped.CurrVArr.Clone(); WillPush.CurrVArr[I] /= 2; //満足度の更新 WillPush.Path = Popped.Path + Environment.NewLine + string.Format("アトラクション{0}(満足度{1})", I, CurrV); //下限値枝切り int RestSum = WillPush.VSum; for (int J = WillPush.CurrP; J <= UB; J++) { int wkV = WillPush.CurrVArr[J]; while (true) { RestSum += wkV; if ((wkV /= 2) == 0) break; } } if (RestSum < AnswerVSum) continue; stk.Push(WillPush); } } //Console.WriteLine("最大満足度={0}", AnswerVSum); //Console.WriteLine(AnswerPath); Console.WriteLine(AnswerVSum); } }