結果

問題 No.38 赤青白ブロック
ユーザー te-sh
提出日時 2016-09-02 13:47:14
言語 D
(dmd 2.109.1)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,029 bytes
コンパイル時間 790 ms
コンパイル使用メモリ 115,328 KB
実行使用メモリ 60,672 KB
最終ジャッジ日時 2024-06-12 04:07:55
合計ジャッジ時間 3,050 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 9 RE * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.conv, std.stdio, std.typecons;

void main()
{
  auto rd = readln.split.map!(to!int);
  auto kr = rd[0], kb = rd[1];
  auto s = readln.chomp;

  int[string] memo;

  bool calc(string t) {
    foreach (i, c; t) {
      switch (c) {
      case 'R':
        if (i < t.length - kr && t[i + kr] == 'R')
          return false;
        break;
      case 'B':
        if (i < t.length - kb && t[i + kb] == 'B')
          return false;
        break;
      default:
      } 
    }

    return true;
  }

  int dp(string t) {
    if (t in memo) return memo[t];

    if (calc(t)) {
      memo[t] = t.length.to!int;
      return t.length.to!int;
    }

    auto maxLen = 0;

    foreach (i, c; t) {
      if (c != 'W') {
        auto r = dp(t[0..i] ~ t[i + 1..$]);
        maxLen = max(maxLen, r);
      }
    }

    memo[t] = maxLen;
    return maxLen;
  }

  writeln(dp(s));
}
0