結果
| 問題 |
No.45 回転寿司
|
| ユーザー |
明智重蔵
|
| 提出日時 | 2015-07-25 20:21:34 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 441 ms / 5,000 ms |
| コード長 | 2,128 bytes |
| コンパイル時間 | 2,947 ms |
| コンパイル使用メモリ | 108,032 KB |
| 実行使用メモリ | 19,712 KB |
| 最終ジャッジ日時 | 2024-12-27 11:56:05 |
| 合計ジャッジ時間 | 9,120 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
コンパイルメッセージ
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 = "Input5";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("4");
WillReturn.Add("1 2 3 4");
}
else if (InputPattern == "Input2") {
WillReturn.Add("4");
WillReturn.Add("5 4 4 9");
}
else if (InputPattern == "Input3") {
WillReturn.Add("7");
WillReturn.Add("1 2 9 10 1 1 4");
}
else if (InputPattern == "Input4") {
WillReturn.Add("1");
WillReturn.Add("100");
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
struct JyoutaiDef
{
internal int CurrP;
internal int SumVal;
}
static void Main()
{
List<string> InputList = GetInputList();
int[] VArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();
int UB = VArr.GetUpperBound(0);
var stk = new Stack<JyoutaiDef>();
JyoutaiDef WillPush;
WillPush.CurrP = 0;
WillPush.SumVal = 0;
stk.Push(WillPush);
int Answer = 0;
//メモ化探索用
var MemoDict = new Dictionary<int, int>();
while (stk.Count > 0) {
JyoutaiDef Popped = stk.Pop();
if (Answer < Popped.SumVal)
Answer = Popped.SumVal;
for (int I = Popped.CurrP; I <= UB && I <= Popped.CurrP + 1; I++) {
WillPush.CurrP = I + 2;
WillPush.SumVal = Popped.SumVal + VArr[I];
if (MemoDict.ContainsKey(WillPush.CurrP)) {
if (MemoDict[WillPush.CurrP] >= WillPush.SumVal)
continue;
}
MemoDict[WillPush.CurrP] = WillPush.SumVal;
stk.Push(WillPush);
}
}
Console.WriteLine(Answer);
}
}
明智重蔵