結果

問題 No.10 +か×か
ユーザー mbanmban
提出日時 2016-11-10 16:53:03
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 1,666 bytes
コンパイル時間 2,768 ms
コンパイル使用メモリ 111,560 KB
実行使用メモリ 23,740 KB
最終ジャッジ日時 2023-08-16 17:37:14
合計ジャッジ時間 3,992 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
19,636 KB
testcase_01 AC 59 ms
23,612 KB
testcase_02 AC 59 ms
21,636 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 60 ms
21,644 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 = 100;
    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