結果

問題 No.10 +か×か
ユーザー YoshiRyuYoshiRyu
提出日時 2016-11-03 02:59:48
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,489 bytes
コンパイル時間 4,006 ms
コンパイル使用メモリ 110,848 KB
実行使用メモリ 27,044 KB
最終ジャッジ日時 2023-08-16 12:58:55
合計ジャッジ時間 9,083 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
23,628 KB
testcase_01 AC 57 ms
21,496 KB
testcase_02 AC 57 ms
21,576 KB
testcase_03 AC 73 ms
19,516 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 Do
{
    private MyConsole mc = new MyConsole();

    public void Solve()
    {
        var N = mc.Int();
        var Total = mc.Int();
        var A = mc.IntSplit();

        bool found = false;

        Func<bool[],int,int, bool> act = null;
        act = ( Formula, Base, Index ) =>
        {
            if (found) return true;

            if (Base < Total && Index < N)
            {
                Formula[Index - 1] = false;
                if (act( Formula, Base + A[Index], Index + 1 )) return true;
                Formula[Index - 1] = true;
                if (act( Formula, Base * A[Index], Index + 1 )) return true;
            }
            else if (Base == Total && Index == N)
            {
                string ans = string.Empty;
                foreach (var item in Formula) ans += item ? "*" : "+";
                mc.wLine( ans );
                found = true;
            }

            return false;
        };

        // 演算の実行
        act( new bool[N - 1], A[0], 1 );
    }
}

public class Program
{
    public static void Main()
    {
        MyConsole.Read();

        var Do = new Do();
        Do.Solve();

        MyConsole.Finish();
    }
}

public class MyConsole
{
    private static List<string> ReadedLine = new List<string>();
    private char[] buf = new char[1024];
    private 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 string String() { return ReadedLine[i++]; }
    public string[] StringSplit() { return ReadedLine[i++].Split( new[] { ' ' } ); }

    public int Int() { return int.Parse( ReadedLine[i++] ); }
    public 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 long Long() { return long.Parse( ReadedLine[i++] ); }
    public double Double() { return double.Parse( ReadedLine[i++] ); }

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

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