結果

問題 No.2278 Time Bomb Game 2
ユーザー siman
提出日時 2023-04-24 13:02:00
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 1,268 bytes
コンパイル時間 363 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 22,912 KB
最終ジャッジ日時 2024-11-08 15:03:27
合計ジャッジ時間 13,214 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 68 WA * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
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