結果

問題 No.38 赤青白ブロック
ユーザー te-shte-sh
提出日時 2017-01-17 17:15:00
言語 D
(dmd 2.106.1)
結果
RE  
実行時間 -
コード長 1,109 bytes
コンパイル時間 881 ms
コンパイル使用メモリ 88,540 KB
実行使用メモリ 4,512 KB
最終ジャッジ日時 2023-09-03 00:42:09
合計ジャッジ時間 3,320 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,384 KB
testcase_01 AC 136 ms
4,384 KB
testcase_02 AC 5 ms
4,380 KB
testcase_03 AC 4 ms
4,384 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 RE -
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 4 ms
4,384 KB
testcase_09 RE -
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,384 KB
testcase_12 AC 4 ms
4,384 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 RE -
testcase_16 AC 17 ms
4,380 KB
testcase_17 RE -
testcase_18 AC 18 ms
4,380 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 4 ms
4,384 KB
testcase_22 RE -
testcase_23 AC 4 ms
4,384 KB
testcase_24 AC 29 ms
4,384 KB
testcase_25 AC 3 ms
4,384 KB
testcase_26 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import core.bitop;    // bit operation

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

  auto bi = bitPos(s);

  auto maxL = 0.to!size_t;
  foreach (i; (1 << 20).iota) {
    if (s.length - i.popcnt <= maxL) continue;
    string t;
    foreach (j; 30.iota)
      if (!bitTest(i, bi[j])) t ~= s[j];
    if (valid(t, kr, kb))
      maxL = max(maxL, t.length);
  }

  writeln(maxL);
}

bool bitTest(T)(T n, size_t i) { return (n & (1.to!T << i)) != 0; }

auto bitPos(string s)
{
  auto j = 0;
  auto bi = new size_t[](30);
  foreach (i, c; s) {
    if (c == 'W') bi[i] = 21;
    else bi[i] = j++;
  }
  return bi;
}

auto valid(T)(T[] s, int kr, int kb)
{
  foreach (i, c; s) {
    switch (c) {
    case 'R':
      if (i >= kr && s[i - kr] == 'R' || i < s.length - kr && s[i + kr] == 'R')
        return false;
      break;
    case 'B':
      if (i >= kb && s[i - kb] == 'B' || i < s.length - kb && s[i + kb] == 'B')
        return false;
      break;
    default:
    }
  }
  return true;
}
0