結果

問題 No.2278 Time Bomb Game 2
ユーザー simansiman
提出日時 2023-04-24 13:07:45
言語 Ruby
(3.3.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 1,268 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 22,912 KB
最終ジャッジ日時 2024-04-26 02:44:41
合計ジャッジ時間 11,184 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
12,160 KB
testcase_01 AC 93 ms
12,160 KB
testcase_02 AC 86 ms
12,288 KB
testcase_03 AC 83 ms
12,288 KB
testcase_04 AC 83 ms
12,416 KB
testcase_05 AC 83 ms
12,160 KB
testcase_06 AC 94 ms
14,464 KB
testcase_07 AC 116 ms
19,584 KB
testcase_08 AC 105 ms
17,280 KB
testcase_09 AC 129 ms
21,888 KB
testcase_10 AC 129 ms
22,656 KB
testcase_11 AC 129 ms
22,656 KB
testcase_12 AC 142 ms
22,656 KB
testcase_13 AC 129 ms
22,656 KB
testcase_14 AC 129 ms
22,656 KB
testcase_15 AC 132 ms
22,784 KB
testcase_16 AC 130 ms
22,528 KB
testcase_17 AC 127 ms
22,912 KB
testcase_18 AC 128 ms
22,912 KB
testcase_19 AC 130 ms
22,784 KB
testcase_20 AC 125 ms
22,656 KB
testcase_21 AC 130 ms
22,912 KB
testcase_22 AC 138 ms
22,528 KB
testcase_23 AC 130 ms
22,784 KB
testcase_24 AC 128 ms
22,784 KB
testcase_25 AC 129 ms
22,912 KB
testcase_26 AC 127 ms
22,656 KB
testcase_27 AC 129 ms
22,656 KB
testcase_28 AC 128 ms
22,784 KB
testcase_29 AC 128 ms
22,784 KB
testcase_30 AC 128 ms
22,656 KB
testcase_31 AC 126 ms
22,784 KB
testcase_32 AC 125 ms
22,656 KB
testcase_33 AC 124 ms
22,656 KB
testcase_34 AC 125 ms
22,656 KB
testcase_35 AC 128 ms
22,656 KB
testcase_36 AC 133 ms
22,528 KB
testcase_37 AC 128 ms
22,912 KB
testcase_38 AC 133 ms
22,656 KB
testcase_39 AC 127 ms
22,784 KB
testcase_40 AC 143 ms
22,784 KB
testcase_41 AC 136 ms
22,784 KB
testcase_42 AC 145 ms
22,656 KB
testcase_43 AC 135 ms
22,656 KB
testcase_44 AC 144 ms
22,784 KB
testcase_45 AC 139 ms
22,656 KB
testcase_46 AC 141 ms
22,656 KB
testcase_47 AC 128 ms
22,656 KB
testcase_48 AC 130 ms
22,784 KB
testcase_49 AC 136 ms
22,912 KB
testcase_50 AC 131 ms
22,656 KB
testcase_51 AC 134 ms
22,784 KB
testcase_52 AC 129 ms
22,656 KB
testcase_53 AC 129 ms
22,656 KB
testcase_54 AC 130 ms
22,784 KB
testcase_55 AC 129 ms
22,656 KB
testcase_56 AC 131 ms
22,784 KB
testcase_57 AC 128 ms
22,912 KB
testcase_58 AC 129 ms
22,784 KB
testcase_59 AC 128 ms
22,784 KB
testcase_60 AC 127 ms
22,656 KB
testcase_61 AC 128 ms
22,784 KB
testcase_62 AC 129 ms
22,656 KB
testcase_63 AC 130 ms
22,912 KB
testcase_64 AC 137 ms
22,656 KB
testcase_65 AC 143 ms
22,784 KB
testcase_66 AC 144 ms
22,784 KB
testcase_67 AC 146 ms
22,784 KB
testcase_68 AC 147 ms
22,784 KB
testcase_69 AC 146 ms
22,784 KB
testcase_70 AC 149 ms
22,656 KB
testcase_71 AC 86 ms
12,160 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, K, T = gets.split.map(&:to_i)
C = gets.chomp.chars

def f(k, t, repeated = false)
  ch = C[k]
  has_same_tile = false

  if k > 0 && C[k - 1] == ch
    has_same_tile = true
  end

  if k + 1 < N && C[k + 1] == ch
    has_same_tile = true
  end

  if has_same_tile
    res = false

    if C[k - 1] == ch
      cur = k
      remain = t

      while cur > 0 && C[cur - 1] == C[cur]
        cur -= 1
        remain -= 1
      end

      if remain > 0 && cur > 0 && C[cur - 1] != C[cur]
        res |= remain.odd?
      end
    end

    if C[k + 1] == ch
      cur = k
      remain = t

      while cur + 1 < N && C[cur] == C[cur + 1]
        cur += 1
        remain -= 1
      end

      if remain > 0 && cur + 1 < N && C[cur] != C[cur + 1]
        res |= remain.odd?
      end
    end

    res
  else
    if t.even?
      false
    else
      if repeated
        false
      else
        res = false

        if t >= 2
          res |= !f(k - 1, t - 1, true) if k - 1 > 0
          res |= !f(k + 1, t - 1, true) if k + 1 < N
        else
          res = true
        end

        res
      end
    end
  end
end

res = f(K - 1, T)

if C[K - 1] == 'A'
  if res
    puts 'Alice'
  else
    puts 'Bob'
  end
else
  if res
    puts 'Bob'
  else
    puts 'Alice'
  end
end
0