結果
| 問題 |
No.2486 Don't come next to me
|
| ユーザー |
|
| 提出日時 | 2023-09-29 22:03:05 |
| 言語 | Fortran (gFortran 14.2.0) |
| 結果 |
AC
|
| 実行時間 | 64 ms / 2,000 ms |
| コード長 | 991 bytes |
| コンパイル時間 | 2,451 ms |
| コンパイル使用メモリ | 32,768 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-22 16:02:47 |
| 合計ジャッジ時間 | 3,575 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
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