結果
問題 | No.38 赤青白ブロック |
ユーザー |
![]() |
提出日時 | 2017-07-26 04:52:26 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,789 bytes |
コンパイル時間 | 825 ms |
コンパイル使用メモリ | 112,332 KB |
実行使用メモリ | 26,196 KB |
最終ジャッジ日時 | 2024-10-09 17:32:18 |
合計ジャッジ時間 | 4,588 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 WA * 10 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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); } }