結果
| 問題 |
No.2426 Select Plus or Minus
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-08-18 21:48:13 |
| 言語 | Fortran (gFortran 14.2.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 846 bytes |
| コンパイル時間 | 403 ms |
| コンパイル使用メモリ | 32,640 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-28 06:31:24 |
| 合計ジャッジ時間 | 1,848 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
ソースコード
program yukicoder_2426
use, intrinsic :: iso_fortran_env
implicit none
integer(int32), parameter :: max_len = 10000
integer(int64) :: n, m
character(len=:), allocatable :: operations
integer(int32) :: k
read(input_unit, *) n
allocate(character(len=max_len) :: operations)
operations(1:max_len) = ""
m = n
do k = 1, max_len
if (m == 1) exit
if (iand(m, b'1') == 0) then
m = m / 2
operations(k:k) = "/"
else !> b is odd.
if (iand((3 * m + 1) / 2, b'1') == 0) then
m = 3 * m + 1
operations(k:k) = "+"
else !> iand((3 * m - 1) / 2, b'1') == 0
m = 3 * m - 1
operations(k:k) = "-"
end if
end if
end do
write(output_unit, '(i0)') len_trim(operations)
write(output_unit, '(a)') trim(operations)
end program yukicoder_2426