結果
問題 | No.3 ビットすごろく |
ユーザー | katsumi |
提出日時 | 2019-01-31 13:51:00 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 815 bytes |
コンパイル時間 | 2,138 ms |
コンパイル使用メモリ | 74,016 KB |
実行使用メモリ | 41,396 KB |
最終ジャッジ日時 | 2024-04-26 21:25:55 |
合計ジャッジ時間 | 15,154 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 130 ms
41,088 KB |
testcase_01 | AC | 129 ms
41,368 KB |
testcase_02 | AC | 2,494 ms
41,396 KB |
testcase_03 | AC | 2,539 ms
40,936 KB |
testcase_04 | AC | 132 ms
41,176 KB |
testcase_05 | TLE | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
ソースコード
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[] map = new int[N+1]; for (int i = 1; i <= N; i++) { map[i] = Integer.bitCount(i); } int ans = 1; int p = 1; while(p != N) { if (p+map[p] == N) { ans++; break; } else if (p+map[p] < N) { p += map[p]; ans++; } else if (p+map[p] > N && p-map[p] > 0) { p -= map[p]; ans++; } else { ans = -1; break; } if (ans > 1000_000_000) { ans = -1; break; } } System.out.println(ans); } }