結果
問題 |
No.3 ビットすごろく
|
ユーザー |
![]() |
提出日時 | 2016-07-23 06:02:05 |
言語 | Fortran (gFortran 14.2.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,359 bytes |
コンパイル時間 | 514 ms |
コンパイル使用メモリ | 30,848 KB |
実行使用メモリ | 813,696 KB |
最終ジャッジ日時 | 2024-11-06 14:24:55 |
合計ジャッジ時間 | 2,697 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 2 MLE * 1 -- * 30 |
ソースコード
logical function is_reacheable(n) implicit none integer::i, n logical::is_reacheablef=.false. if (n.eq.1) then is_reacheablef = .true. return end if do i=max(1,n-(31-LEADZ(10000))), n if (n.eq.POPCNT(i)+i) then is_reacheable = .true. exit end if end do end function is_reacheable recursive function progress(pos, goal, step) result(total_step) implicit none logical,save::reached=.false. integer::pos, goal, step integer::popcount integer::total_step if (pos .eq. goal) then total_step = step return else popcount = POPCNT(pos) if (pos + popcount .le. goal) then total_step = progress(pos + popcount, goal, step + 1) else if (pos - popcount .ge. 1) then total_step = progress(pos - popcount, goal, step + 1) end if end if end function progress program main implicit none interface logical function is_reacheable(n) integer::n end function is_reacheable recursive function progress(pos, goal, step) result(total_step) integer::pos, goal, step integer::total_step end function progress end interface integer::N,total_step read *,N if(is_reacheable(N).eqv..false.) then print '(a)',"-1" return endif total_step = progress(1, N, 1) print '(i0)', total_step end program main