結果

問題 No.10 +か×か
ユーザー YoshiRyuYoshiRyu
提出日時 2016-11-03 05:13:55
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 155 ms / 5,000 ms
コード長 2,335 bytes
コンパイル時間 2,260 ms
コンパイル使用メモリ 107,240 KB
実行使用メモリ 29,980 KB
最終ジャッジ日時 2023-08-21 06:21:00
合計ジャッジ時間 3,961 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
19,584 KB
testcase_01 AC 60 ms
21,580 KB
testcase_02 AC 60 ms
21,444 KB
testcase_03 AC 124 ms
25,712 KB
testcase_04 AC 63 ms
21,836 KB
testcase_05 AC 60 ms
23,632 KB
testcase_06 AC 155 ms
29,980 KB
testcase_07 AC 107 ms
25,956 KB
testcase_08 AC 65 ms
26,004 KB
testcase_09 AC 68 ms
26,200 KB
testcase_10 AC 60 ms
23,660 KB
testcase_11 AC 60 ms
21,568 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.IO;
using System.Linq;

public class YukiCoder
{
    public static void Solve()
    {
        var N = MyConsole.Int();
        var Total = MyConsole.Int();
        var A = MyConsole.IntSplit();
        
        bool found = false;

        var roadmap = new bool[N + 1, Total + 1];

        Action<string,int,int> act = null;

        act = ( Formula, Base, Index ) =>
        {
            if (found || Base > Total || roadmap[Index, Base]) return;

            if (Base == Total && Index == N)
            {
                MyConsole.wLine( Formula );
                found = true;
                return;
            }

            roadmap[Index, Base] = true;

            if (Index == N) return;

            act( Formula + "+", Base + A[Index], Index + 1 );
            act( Formula + "*", Base * A[Index], Index + 1 );
        };

        // 演算の実行
        act( "", A[0], 1 );
    }

    public static void Main()
    {
        MyConsole.Read(); Solve(); MyConsole.Finish();
    }
}

public static class MyConsole
{
    private static List<string> ReadedLine = new List<string>();
    private static char[] buf = new char[1024];
    private static int i;

    public static void Read()
    {
        string sr = Console.In.ReadToEnd();

        ReadedLine = sr.Split( new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries ).ToList();

        Console.SetOut( new StreamWriter( Console.OpenStandardOutput() ) { AutoFlush = false } );
    }

    public static string String() { return ReadedLine[i++]; }
    public static string[] StringSplit() { return ReadedLine[i++].Split( new[] { ' ' } ); }

    public static int Int() { return int.Parse( ReadedLine[i++] ); }
    public static int[] IntSplit()
    {
        string[] strs = StringSplit();
        int[] ret = new int[strs.Length];
        for (int i = 0 ; i < strs.Length ; i++)
        {
            ret[i] = int.Parse( strs[i] );
        }

        return ret;
    }
    public static long Long() { return long.Parse( ReadedLine[i++] ); }
    public static double Double() { return double.Parse( ReadedLine[i++] ); }

    public static void wLine( string output = null )
    {
        Console.WriteLine( output );
    }

    public static void Finish()
    {
        Console.Out.Flush();
    }
}
0