結果

問題 No.10 +か×か
ユーザー mbanmban
提出日時 2016-11-10 16:56:50
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,592 ms / 5,000 ms
コード長 1,678 bytes
コンパイル時間 2,244 ms
コンパイル使用メモリ 107,708 KB
実行使用メモリ 350,988 KB
最終ジャッジ日時 2023-08-21 06:21:26
合計ジャッジ時間 7,712 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
21,240 KB
testcase_01 AC 59 ms
21,756 KB
testcase_02 AC 60 ms
23,708 KB
testcase_03 AC 1,560 ms
350,988 KB
testcase_04 AC 85 ms
29,832 KB
testcase_05 AC 77 ms
25,384 KB
testcase_06 AC 1,592 ms
345,412 KB
testcase_07 AC 757 ms
153,508 KB
testcase_08 AC 234 ms
64,444 KB
testcase_09 AC 124 ms
46,796 KB
testcase_10 AC 62 ms
23,880 KB
testcase_11 AC 60 ms
23,204 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;

class Magatro
{
    static int N;
    static int Total;
    static int[] A;
    const int MAX = 100000;
    static void Main()
    {
        Read();
        string[,] ans = new string[N, MAX+1];
        ans[1, A[0] * A[1]] = "*";
        ans[1, A[0] + A[1]] = "+";
        

        for (int j = 2; j < N; j++)
        {
            for (int i = 0; i <= MAX; i++)
            {
                if (ans[j-1, i] != null)
                {
                    if (i * A[j] <= MAX)
                    {
                        ans[j, i * A[j]] = Min(ans[j - 1, i] + "*",ans[j,i*A[j]]);
                    }
                    if (i + A[j] <= MAX)
                    {
                        ans[j, i + A[j]] =Min( ans[j - 1, i] + "+", ans[j, i + A[j]]);
                    }
                }  
            }
        }
        Console.WriteLine(ans[N - 1, Total]);
    }
   static void Read()
    {
        N = int.Parse(Console.ReadLine());
        Total = int.Parse(Console.ReadLine());
        A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
    }
    static string Min(string a,string b)
    {
        if (a == null)
        {
            return b;
        }
        if (b == null)
        {
            return a;
        }
        for(int i = 0; i < Math.Min(a.Length, b.Length); i++)
        {
            if (a[i] != b[i])
            {
                if (a[i] == '+')
                {
                    return a;
                }
                else
                {
                    return b;
                }
            }
        }
        return "Dummy";
    }
}
0