結果

問題 No.38 赤青白ブロック
ユーザー mban
提出日時 2017-07-26 05:00:54
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 498 ms / 5,000 ms
コード長 1,493 bytes
コンパイル時間 5,602 ms
コンパイル使用メモリ 112,996 KB
実行使用メモリ 30,384 KB
最終ジャッジ日時 2024-12-23 13:09:11
合計ジャッジ時間 10,806 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
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, string s)
    {
        if (n == Length)
        {
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == 'R' && i - Kr >= 0)
                {
                    if(s[i] == s[i - Kr])
                    {
                        return;
                    }
                }
                else if (s[i] == 'B' && i - Kb >= 0)
                {
                    if(s[i] == s[i - Kb])
                    {
                        return;
                    }
                }
            }
            ans = Math.Max(ans, s.Length);
            return;
        }
        if (S[n] != 'W')
        {
            DFS(n + 1, s);
        }
        DFS(n + 1, s + S[n]);
    }

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