結果

問題 No.38 赤青白ブロック
ユーザー mbanmban
提出日時 2017-07-26 04:52:26
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,789 bytes
コンパイル時間 712 ms
コンパイル使用メモリ 111,560 KB
実行使用メモリ 26,268 KB
最終ジャッジ日時 2024-04-17 23:44:48
合計ジャッジ時間 4,038 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 42 ms
24,096 KB
testcase_02 AC 44 ms
24,096 KB
testcase_03 AC 43 ms
26,004 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 31 ms
26,144 KB
testcase_07 WA -
testcase_08 AC 152 ms
23,852 KB
testcase_09 WA -
testcase_10 AC 163 ms
24,104 KB
testcase_11 AC 146 ms
21,816 KB
testcase_12 AC 69 ms
24,108 KB
testcase_13 AC 150 ms
26,260 KB
testcase_14 AC 63 ms
23,980 KB
testcase_15 AC 141 ms
24,164 KB
testcase_16 AC 26 ms
25,884 KB
testcase_17 AC 66 ms
25,948 KB
testcase_18 WA -
testcase_19 AC 98 ms
23,904 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 154 ms
23,856 KB
testcase_24 AC 31 ms
24,028 KB
testcase_25 AC 95 ms
24,232 KB
testcase_26 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;

class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    private int Kr, Kb;
    private string S;
    private int ans = 0;
    private const int Length = 30;
    private bool[] Use = new bool[Length];

    private void Scan()
    {
        var line = Console.ReadLine().Split(' ');
        Kr = int.Parse(line[0]);
        Kb = int.Parse(line[1]);
        S = Console.ReadLine();
    }

    private void DFS(int n, int l)
    {
        if (n == Length)
        {
            ans = Math.Max(ans, l);
            return;
        }
        if (S[n] == 'W')
        {
            Use[n] = true;
            DFS(n + 1, l + 1);
        }
        else
        {
            DFS(n + 1, l);
            int cnt = 0;
            Use[n] = true;
            if (S[n] == 'R')
            {
                for (int i = n - 1; i >= 0; i--)
                {
                    if (Use[i]) cnt++;
                    if (cnt == Kr && S[i] == 'R')
                    {
                        return;
                    }
                }
            }
            else if (S[n] == 'B')
            {
                for (int i = n - 1; i >= 0; i--)
                {
                    if (Use[i]) cnt++;
                    if (cnt == Kb && S[i] == 'B')
                    {
                        return;
                    }
                }
            }
            DFS(n + 1, l + 1);
            Use[n] = false;
        }
    }

    public void Solve()
    {
        Scan();
        DFS(0, 0);
        Console.WriteLine(ans);
    }
}
0