結果

問題 No.10 +か×か
ユーザー YoshiRyuYoshiRyu
提出日時 2016-11-03 01:14:26
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,691 bytes
コンパイル時間 3,109 ms
コンパイル使用メモリ 105,608 KB
実行使用メモリ 27,756 KB
最終ジャッジ日時 2023-08-16 12:52:49
合計ジャッジ時間 9,131 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
25,964 KB
testcase_01 AC 59 ms
23,548 KB
testcase_02 AC 58 ms
23,656 KB
testcase_03 AC 193 ms
27,756 KB
testcase_04 TLE -
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.Collections.Generic;
using System.IO;
using System.Linq;

public class YukiCoder
{
    private static int N;
    private static int Total;
    private static int[] A;

    public static void Solve()
    {
        N = MyConsole.Int();
        Total = MyConsole.Int();
        A = MyConsole.IntSplit();

        try
        {
            // 演算の実行
            Math( "", A[0], 1 );
        }
        catch { }
    }

    /// <summary>
    /// Total に達するまで+と×の組み合わせを変えながら演算を行う。
    /// 組み合わせは辞書順の上から総当りの手法。
    /// </summary>
    /// <param name="Formula">計算式</param>
    /// <param name="Base">経過値</param>
    /// <param name="Index">位置情報</param>
    /// <returns>終わっている?[true:終わった false:まだまだ!] </returns>
    private static void Math( string Formula, int Base, int Index )
    {
        if (Base < Total && Index < N)
        {
            Math( Formula + "+", Base + A[Index], Index + 1 );
            Math( Formula + "*", Base * A[Index], Index + 1 );
        }
        else if (Base == Total && Index == N)
        {
            MyConsole.wLine( Formula );
            throw new NullReferenceException("おわり");
        }
    }

    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