結果
| 問題 |
No.37 遊園地のアトラクション
|
| コンテスト | |
| ユーザー |
明智重蔵
|
| 提出日時 | 2015-07-25 18:19:51 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 37 ms / 5,000 ms |
| コード長 | 2,742 bytes |
| コンパイル時間 | 5,142 ms |
| コンパイル使用メモリ | 109,572 KB |
| 実行使用メモリ | 20,480 KB |
| 最終ジャッジ日時 | 2024-10-10 13:02:28 |
| 合計ジャッジ時間 | 3,745 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 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 = "Input5";
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;
}
static void Main()
{
var sw = System.Diagnostics.Stopwatch.StartNew();
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();
//添字が時間の合計、値が満足度合計の最大値
var SumVArr = new Nullable<int>[T + 1];
SumVArr[0] = 0;
int KasanValue = 0;
for (int LoopI = 0; LoopI <= CArr.GetUpperBound(0); LoopI += KasanValue) {
for (int LoopJ = T; 0 <= LoopJ; LoopJ--) {
//時間制限を超えてしまう場合
int wkSumC = LoopJ + CArr[LoopI];
if (wkSumC > T) continue;
//満足度の和を求める
if (SumVArr[LoopJ] == null) continue;
int wkSumV = (SumVArr[LoopJ] ?? 0) + VArr[LoopI];
//満足度合計での最大の満足度を更新可能かを判定
bool CanUpdate = false;
if (SumVArr[wkSumC] == null) CanUpdate = true;
else if (SumVArr[wkSumC] < wkSumV) CanUpdate = true;
if (CanUpdate) {
SumVArr[wkSumC] = wkSumV;
}
}
//同じアトラクションに乗った場合は、満足度は半分
VArr[LoopI] /= 2;
KasanValue = (VArr[LoopI] == 0 ? 1 : 0);
}
Console.WriteLine(SumVArr.Max(X => X ?? 0));
}
}
明智重蔵