結果

問題 No.153 石の山
ユーザー keiden
提出日時 2024-09-20 23:34:38
言語 Scheme
(Gauche-0.9.15)
結果
AC  
実行時間 97 ms / 5,000 ms
コード長 1,031 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 7,068 KB
実行使用メモリ 23,296 KB
最終ジャッジ日時 2024-09-20 23:34:50
合計ジャッジ時間 4,058 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

(use scheme.bitwise)

(define (f n)
  (let
    ((grundy (make-vector 101 0)))
    (vector-set! grundy 2 1)
    (do
      ((i 3 (+ i 1)))
      ((> i n))
      (let*
        (
          (a
            (bitwise-xor
              (vector-ref grundy (quotient i 3))
              (vector-ref grundy (+ (quotient i 3) (if (> (remainder i 3) 0) 1 0)))
              (vector-ref grundy (+ (quotient i 3) (if (> (remainder i 3) 1) 1 0)))))
          (b
            (bitwise-xor
              (vector-ref grundy (quotient i 2))
              (vector-ref grundy (+ (quotient i 2) (if (= (remainder i 2) 1) 1 0)))))
        )
        (let loop ()
          (when (or (= (vector-ref grundy i) a) (= (vector-ref grundy i) b))
            (vector-set! grundy i (+ 1 (vector-ref grundy i)))
            (loop)
          )
        )
      )
    )
    grundy
  )
)

(define yuki153
  (let* ((n (read)) (grundy (f n)))
    (if (= n 1)
      (display "B\n")
      (if (zero? (vector-ref grundy n))
        (display "B\n")
        (display "A\n")))))
0