結果
| 問題 | No.2486 Don't come next to me |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-09-29 22:03:05 |
| 言語 | Fortran (gFortran 16.2.0) |
| 結果 |
WJ
不安定
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 991 bytes |
| 記録 | |
| 最終ジャッジ日時 | 2026-08-23 09:46:27 |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
ソースコード
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