結果

問題 No.38 赤青白ブロック
ユーザー te-shte-sh
提出日時 2016-09-02 13:47:14
言語 D
(dmd 2.107.1)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,029 bytes
コンパイル時間 738 ms
コンパイル使用メモリ 102,520 KB
実行使用メモリ 61,432 KB
最終ジャッジ日時 2023-09-02 21:52:47
合計ジャッジ時間 3,619 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 68 ms
13,056 KB
testcase_02 AC 339 ms
35,248 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 2 ms
4,368 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 1 ms
4,372 KB
testcase_11 AC 2 ms
4,372 KB
testcase_12 AC 1 ms
4,372 KB
testcase_13 AC 1 ms
4,372 KB
testcase_14 AC 1 ms
4,372 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 AC 672 ms
61,432 KB
testcase_25 RE -
testcase_26 RE -
権限があれば一括ダウンロードができます

ソースコード

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