結果

問題 No.8 N言っちゃダメゲーム
ユーザー osada-yumosada-yum
提出日時 2023-10-30 16:39:31
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 1,064 bytes
コンパイル時間 446 ms
コンパイル使用メモリ 33,164 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-30 16:39:35
合計ジャッジ時間 1,431 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 8 ms
4,348 KB
testcase_04 AC 17 ms
4,348 KB
testcase_05 AC 6 ms
4,348 KB
testcase_06 AC 5 ms
4,348 KB
testcase_07 AC 6 ms
4,348 KB
testcase_08 AC 6 ms
4,348 KB
testcase_09 AC 6 ms
4,348 KB
testcase_10 AC 7 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

program yukicoder_8
  use, intrinsic :: iso_fortran_env
  implicit none
  integer(int32) :: p
  integer(int32) :: n, k
  integer(int32) :: i
  read(input_unit, *) p
  do i = 1, p
     read(input_unit, *) n, k
     call solve(n, k)
  end do
contains
  impure subroutine solve(n, k)
    integer(int32), intent(in) :: n, k
    logical :: dp(0:n) !> そのターンの人が勝つか.
    integer(int32) :: n_true
    integer(int32) :: i
    dp(n - 1:n) = .false.
    dp(max(0, n - k - 1):n - 2) = .true.
    if (n - k - 1 <= 0) then
       write(output_unit, '(a)') "Win"
       return
    end if
    n_true = count(dp(n - k:n - 1)) !> i == n - k -  1 とすると, dp(n - k:n - 1) の .true. の数.
    do i = n - k - 2, 0, -1
       if (dp(i + k + 1)) n_true = n_true - 1
       if (dp(i + 1)) n_true = n_true + 1
       !> dp(i + 1:i + k) が全て .true. なら負け. ひとつでも .false. があれば勝ち.
       dp(i) = n_true < k
    end do
    write(output_unit, '(a)') trim(merge("Win ", "Lose", dp(0)))
  end subroutine solve
end program yukicoder_8
0