結果

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

テストケース

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

ソースコード

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 + kr < s.length && s[i + kr] == 'R')
        return false;
      break;
    case 'B':
      if (i >= kb && s[i - kb] == 'B' || i + kb < s.length && s[i + kb] == 'B')
        return false;
      break;
    default:
    }
  }
  return true;
}
0