結果

問題 No.10 +か×か
ユーザー AreTrashAreTrash
提出日時 2016-04-14 03:07:58
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,594 ms / 5,000 ms
コード長 1,760 bytes
コンパイル時間 2,173 ms
コンパイル使用メモリ 107,452 KB
実行使用メモリ 353,256 KB
最終ジャッジ日時 2023-08-21 06:18:30
合計ジャッジ時間 7,513 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
21,728 KB
testcase_01 AC 60 ms
21,540 KB
testcase_02 AC 58 ms
21,448 KB
testcase_03 AC 1,594 ms
348,668 KB
testcase_04 AC 78 ms
26,632 KB
testcase_05 AC 61 ms
23,464 KB
testcase_06 AC 1,537 ms
353,256 KB
testcase_07 AC 634 ms
126,568 KB
testcase_08 AC 129 ms
41,032 KB
testcase_09 AC 109 ms
38,852 KB
testcase_10 AC 60 ms
21,528 KB
testcase_11 AC 59 ms
23,492 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.Generic;
using System.Linq;

namespace No10_3{
    public class Program{
        public static void Main(string[] args){
            var n = Read(Convert.ToInt32);
            var total = Read(Convert.ToInt32);
            var an = ReadList(Convert.ToInt32);
            var dpAry = new string[n + 1, total + 1];

            if(an[0] * an[1] <= total)
                dpAry[1, an[0] * an[1]] = "*";
            if(an[0] + an[1] <= total)
                dpAry[1, an[0] + an[1]] = "+";

            for(var i = 2; i < n; i++){
                for(var j = 1; j <= total; j++){
                    if(dpAry[i - 1, j] != null){
                        if(j * an[i] <= total){
                            if(dpAry[i, j * an[i]] == null ||
                               string.CompareOrdinal(dpAry[i, j * an[i]], dpAry[i - 1, j] + "*") < 0)
                                dpAry[i, j * an[i]] = dpAry[i - 1, j] + "*";
                        }
                        if(j + an[i] <= total){
                            if(dpAry[i, j + an[i]] == null ||
                               string.CompareOrdinal(dpAry[i, j + an[i]], dpAry[i - 1, j] + "+") < 0)
                                dpAry[i, j + an[i]] = dpAry[i - 1, j] + "+";
                        }
                    }
                }
            }

            Console.WriteLine(dpAry[n - 1, total]);
        }

        public static TOutput Read<TOutput>(Converter<string, TOutput> converter){
            return converter(Console.ReadLine());
        }

        public static List<TOutput> ReadList<TOutput>(Converter<string, TOutput> converter, char c = ' '){
            return Console.ReadLine()?.Split(c).ToList().ConvertAll(converter);
        }
    }
}
0