結果

問題 No.3 ビットすごろく
ユーザー osada-yumosada-yum
提出日時 2023-07-25 20:17:25
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 781 bytes
コンパイル時間 647 ms
コンパイル使用メモリ 32,640 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 11:54:46
合計ジャッジ時間 1,468 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 3 ms
6,944 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 3 ms
6,940 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 3 ms
6,944 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 3 ms
6,944 KB
testcase_26 AC 1 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 3 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 1 ms
6,940 KB
testcase_31 AC 1 ms
6,944 KB
testcase_32 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

program yukicoder_3
  use, intrinsic :: iso_fortran_env
  implicit none
  integer(int32), parameter :: infini = ishft(1, 28)
  integer(int32) :: n
  integer(int32), allocatable :: dp(:)
  read(input_unit, *) n
  allocate(dp(n), source = infini)
  dp(1) = 1_int32
  call dfs(1)
  write(output_unit, '(i0)') merge(dp(n), -1, dp(n) /= infini)
contains
  recursive subroutine dfs(v)
    integer(int32), intent(in) :: v
    integer(int32) :: diff, nv
    integer(int32), parameter :: factor(1:2) = [1, -1]
    integer(int32) :: i
    diff = popcnt(v)
    do i = 1, size(factor)
       nv = v + factor(i)*diff
       if (nv < 1 .or. nv > n) cycle
       if (dp(v) + 1 >= dp(nv)) cycle
       dp(nv) = dp(v) + 1
       call dfs(nv)
    end do
  end subroutine dfs
end program yukicoder_3
0