結果

問題 No.2486 Don't come next to me
ユーザー osada-yumosada-yum
提出日時 2023-09-29 22:03:05
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 991 bytes
コンパイル時間 1,462 ms
コンパイル使用メモリ 26,680 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-29 22:03:09
合計ジャッジ時間 3,856 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
4,376 KB
testcase_01 AC 69 ms
4,380 KB
testcase_02 AC 21 ms
4,376 KB
testcase_03 AC 49 ms
4,380 KB
testcase_04 AC 66 ms
4,380 KB
testcase_05 AC 49 ms
4,376 KB
testcase_06 AC 55 ms
4,380 KB
testcase_07 AC 11 ms
4,380 KB
testcase_08 AC 22 ms
4,380 KB
testcase_09 AC 67 ms
4,376 KB
testcase_10 AC 51 ms
4,376 KB
testcase_11 AC 30 ms
4,376 KB
testcase_12 AC 15 ms
4,376 KB
testcase_13 AC 89 ms
4,504 KB
testcase_14 AC 25 ms
4,376 KB
testcase_15 AC 50 ms
4,380 KB
testcase_16 AC 12 ms
4,380 KB
testcase_17 AC 21 ms
4,376 KB
testcase_18 AC 19 ms
4,376 KB
testcase_19 AC 23 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

program yukicoder2486
  use, intrinsic :: iso_fortran_env
  implicit none
  integer(int64) :: n, diff, ans
  integer(int32) :: m
  integer(int64), allocatable :: arr(:)
  integer(int32) :: i
  read(input_unit, *) n, m
  allocate(arr(m))
  read(input_unit, *) arr(:)
  ans = 0_int64
  do i = 1, m - 1
     diff = arr(i + 1) - arr(i) - 1
     ans = ans + calc_num_last(diff)
  end do
  write(output_unit, '(i0)') ans
contains
  pure recursive integer(int64) function calc_num_last(x) result(res)
    integer(int64), intent(in) :: x
    res = 0_int64; if (x == 0) return
    res = 1_int64; if (x == 1) return
    res = 2_int64; if (x == 2) return
    !> 3 _ _ _ -> _ | _
    !> 5 _ _ _ _ _ -> _ _ | _ _
    if (iand(x, b'1') == 1) then
       res = 2 * calc_num_last(x / 2)
    else !> x is even
       !> 4 _ _ _ _ -> _ | | _
       !> 6 _ _ _ _ _ _ -> _ _ | | _ _
       !> 8 _ _ _ _ _ _ _ _ -> _ _ _ | | _ _ _
       res = x
    end if
  end function calc_num_last
end program yukicoder2486
0