結果

問題 No.158 奇妙なお使い
ユーザー eitahoeitaho
提出日時 2015-03-04 20:58:49
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 2,502 ms / 5,000 ms
コード長 2,908 bytes
コンパイル時間 3,383 ms
コンパイル使用メモリ 110,692 KB
実行使用メモリ 42,952 KB
最終ジャッジ日時 2023-09-11 08:00:09
合計ジャッジ時間 9,815 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
24,236 KB
testcase_01 AC 76 ms
26,648 KB
testcase_02 AC 64 ms
25,720 KB
testcase_03 AC 63 ms
25,356 KB
testcase_04 AC 2,502 ms
42,952 KB
testcase_05 AC 63 ms
23,284 KB
testcase_06 AC 63 ms
23,280 KB
testcase_07 AC 63 ms
23,276 KB
testcase_08 AC 64 ms
23,792 KB
testcase_09 AC 67 ms
25,572 KB
testcase_10 AC 67 ms
24,328 KB
testcase_11 AC 66 ms
25,524 KB
testcase_12 AC 64 ms
26,140 KB
testcase_13 AC 64 ms
23,856 KB
testcase_14 AC 75 ms
28,912 KB
testcase_15 AC 108 ms
27,408 KB
testcase_16 AC 100 ms
31,464 KB
testcase_17 AC 308 ms
36,416 KB
testcase_18 AC 89 ms
26,324 KB
testcase_19 AC 65 ms
23,340 KB
testcase_20 AC 76 ms
28,772 KB
testcase_21 AC 64 ms
23,748 KB
testcase_22 AC 65 ms
26,516 KB
testcase_23 AC 72 ms
30,428 KB
testcase_24 AC 70 ms
27,488 KB
testcase_25 AC 64 ms
23,588 KB
testcase_26 AC 74 ms
24,592 KB
testcase_27 AC 65 ms
23,896 KB
testcase_28 AC 184 ms
31,736 KB
testcase_29 AC 63 ms
23,364 KB
testcase_30 AC 192 ms
26,108 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.IO;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Enu = System.Linq.Enumerable;

class Program
{
    int?[, ,] memo = new int?[11, 101, 10001];
    int[] Need = new int[2];
    int[][] Gain = new int[2][];

    void Solve()
    {
        var A = reader.IntArray(3);
        Need[0] = reader.Int();
        Gain[0] = reader.IntArray(3);
        Need[1] = reader.Int();
        Gain[1] = reader.IntArray(3);
        int ans = Rec(A[0], A[1], A[2]);
        Console.WriteLine(ans);
    }

    private int Rec(int x, int y, int z)
    {
        if (memo[x, y, z].HasValue) return memo[x, y, z].Value;
        int res = 0;
        for (int useX = 0; useX <= x; useX++)
            for (int useY = 0; useY <= y; useY++)
                for (int who = 0; who < 2; who++)
                {
                    int rem = Need[who] - useX * 1000 - useY * 100;
                    if (rem >= 0 && z >= rem)
                    {
                        int curr = 1 + Rec(x - useX + Gain[who][0], y - useY + Gain[who][1], z - rem + Gain[who][2]);
                        res = Math.Max(res, curr);
                    }
                }
        memo[x, y, z] = res;
        return res;
    }





    Reader reader = new Reader(Console.In);
    static void Main() { new Program().Solve(); }
}

class Reader
{
    private readonly TextReader reader;
    private readonly char[] separator = { ' ' };
    private readonly StringSplitOptions removeOp = StringSplitOptions.RemoveEmptyEntries;
    private string[] A = new string[0];
    private int i;

    public Reader(TextReader r) { reader = r; }
    public Reader(string file) { reader = new StreamReader(file); }
    public bool HasNext() { return Enqueue(); }
    public string String() { return Dequeue(); }
    public int Int() { return int.Parse(Dequeue()); }
    public long Long() { return long.Parse(Dequeue()); }
    public double Double() { return double.Parse(Dequeue()); }
    public int[] IntLine() { var s = Line(); return s == "" ? new int[0] : Array.ConvertAll(Split(s), int.Parse); }
    public int[] IntArray(int N) { return Enu.Range(0, N).Select(i => Int()).ToArray(); }
    public int[][] IntGrid(int H) { return Enu.Range(0, H).Select(i => IntLine()).ToArray(); }
    public string[] StringArray(int N) { return Enu.Range(0, N).Select(i => Line()).ToArray(); }
    public string Line() { return reader.ReadLine().Trim(); }
    private string[] Split(string s) { return s.Split(separator, removeOp); }
    private bool Enqueue()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return Enqueue();
        A = Split(line);
        i = 0;
        return true;
    }
    private string Dequeue() { Enqueue(); return A[i++]; }
}
0