結果
| 問題 | No.2278 Time Bomb Game 2 | 
| コンテスト | |
| ユーザー |  siman | 
| 提出日時 | 2023-04-24 13:07:45 | 
| 言語 | Ruby (3.4.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 148 ms / 2,000 ms | 
| コード長 | 1,268 bytes | 
| コンパイル時間 | 447 ms | 
| コンパイル使用メモリ | 7,424 KB | 
| 実行使用メモリ | 22,912 KB | 
| 最終ジャッジ日時 | 2024-11-08 15:09:14 | 
| 合計ジャッジ時間 | 12,514 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 70 | 
コンパイルメッセージ
Syntax OK
ソースコード
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
            
            
            
        