結果

問題 No.2278 Time Bomb Game 2
ユーザー siman
提出日時 2023-04-24 12:56:39
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 1,198 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 22,912 KB
最終ジャッジ日時 2024-11-08 14:59:37
合計ジャッジ時間 12,939 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 31 WA * 39
権限があれば一括ダウンロードができます
コンパイルメッセージ
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?
      true
    else
      if repeated
        true
      else
        res = false

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

        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