結果

問題 No.37 遊園地のアトラクション
ユーザー mbanmban
提出日時 2017-07-26 04:20:37
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 32 ms / 5,000 ms
コード長 1,472 bytes
コンパイル時間 1,143 ms
コンパイル使用メモリ 109,296 KB
実行使用メモリ 27,424 KB
最終ジャッジ日時 2024-04-18 19:57:32
合計ジャッジ時間 3,029 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
27,408 KB
testcase_01 AC 26 ms
25,124 KB
testcase_02 AC 31 ms
25,256 KB
testcase_03 AC 26 ms
23,352 KB
testcase_04 AC 28 ms
27,420 KB
testcase_05 AC 27 ms
24,992 KB
testcase_06 AC 30 ms
25,128 KB
testcase_07 AC 28 ms
25,520 KB
testcase_08 AC 28 ms
25,128 KB
testcase_09 AC 29 ms
27,100 KB
testcase_10 AC 32 ms
25,252 KB
testcase_11 AC 27 ms
25,108 KB
testcase_12 AC 30 ms
25,380 KB
testcase_13 AC 29 ms
25,080 KB
testcase_14 AC 26 ms
27,292 KB
testcase_15 AC 29 ms
27,424 KB
testcase_16 AC 27 ms
25,384 KB
testcase_17 AC 28 ms
25,508 KB
testcase_18 AC 28 ms
27,136 KB
testcase_19 AC 30 ms
25,124 KB
testcase_20 AC 29 ms
25,132 KB
testcase_21 AC 29 ms
27,396 KB
testcase_22 AC 28 ms
27,144 KB
testcase_23 AC 30 ms
25,292 KB
testcase_24 AC 25 ms
23,096 KB
testcase_25 AC 30 ms
27,168 KB
testcase_26 AC 25 ms
25,376 KB
testcase_27 AC 27 ms
23,348 KB
testcase_28 AC 29 ms
25,144 KB
testcase_29 AC 30 ms
25,412 KB
testcase_30 AC 29 ms
25,136 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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());
    }
}
0