結果

問題 No.10 +か×か
ユーザー NoNo
提出日時 2017-05-19 19:36:00
言語 C#(csc)
(csc 3.9.0)
結果
MLE  
実行時間 -
コード長 1,551 bytes
コンパイル時間 960 ms
コンパイル使用メモリ 110,940 KB
実行使用メモリ 821,792 KB
最終ジャッジ日時 2023-10-19 02:50:17
合計ジャッジ時間 7,672 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
25,464 KB
testcase_01 AC 42 ms
26,312 KB
testcase_02 AC 31 ms
25,460 KB
testcase_03 MLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Linq;
using System.Collections.Generic;

namespace Yuki
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int total = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            var lii = new List<int>();
            var lis = new List<string>();
            lii.Add(a[0]);
            lis.Add("");


            for (int i = 1; i < a.Length; i++)
            {
                var lii2 = new List<int>();
                var lis2 = new List<string>();

                for (int j = 0; j < lii.Count; j++)
                {
                    int s = lii[j] + a[i];
                    if (s <= total)
                    {
                        lii2.Add(s);
                        lis2.Add(lis[j] + "+");
                    }

                    int p = lii[j] * a[i];
                    if (p <= total)
                    {
                        lii2.Add(p);
                        lis2.Add(lis[j] + "*");
                    }
                }
                lii = lii2;
                lis = lis2;
            }

            var ans = new List<string>();
            for (int i = 0; i < lii.Count; i++)
            {
                if (lii[i] == total)
                {
                    ans.Add(lis[i]);
                }
            }
            ans.Sort();
            ans.Reverse();

            Console.WriteLine(ans[0]);
        }
    }
}
0