結果
| 問題 |
No.37 遊園地のアトラクション
|
| コンテスト | |
| ユーザー |
mban
|
| 提出日時 | 2017-07-26 04:20:37 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 34 ms / 5,000 ms |
| コード長 | 1,472 bytes |
| コンパイル時間 | 1,134 ms |
| コンパイル使用メモリ | 114,880 KB |
| 実行使用メモリ | 27,372 KB |
| 最終ジャッジ日時 | 2024-10-10 13:21:10 |
| 合計ジャッジ時間 | 2,974 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;
class Program
{
static void Main()
{
new Magatro().Solve();
}
}
class Magatro
{
private int T, N;
private int[] C, V;
private void Scan()
{
T = int.Parse(Console.ReadLine());
N = int.Parse(Console.ReadLine());
C = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
V = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
}
private int[] F(int n)
{
List<int> result = new List<int>();
result.Add(0);
while (n > 0)
{
result.Add(result.Last() + n);
n /= 2;
}
return result.ToArray();
}
public void Solve()
{
Scan();
var dp = (new int[T + 1]).Select(i => -1).ToArray();
dp[0] = 0;
for (int i = 0; i < N; i++)
{
var l = F(V[i]);
for (int j = T; j >= 0; j--)
{
if (dp[j] == -1) continue;
for (int k = 0; k < l.Length; k++)
{
int next = j + C[i] * k;
if (next > T) continue;
dp[next] = Math.Max(dp[next], dp[j] + l[k]);
}
}
}
Console.WriteLine(dp.Max());
}
}
mban