結果
問題 | No.3 ビットすごろく |
ユーザー | actu3 |
提出日時 | 2015-06-20 14:36:36 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 138 ms / 5,000 ms |
コード長 | 2,046 bytes |
コンパイル時間 | 3,645 ms |
コンパイル使用メモリ | 77,608 KB |
実行使用メモリ | 38,608 KB |
最終ジャッジ日時 | 2024-07-01 07:27:01 |
合計ジャッジ時間 | 7,833 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
37,200 KB |
testcase_01 | AC | 55 ms
37,348 KB |
testcase_02 | AC | 55 ms
37,148 KB |
testcase_03 | AC | 77 ms
38,096 KB |
testcase_04 | AC | 64 ms
37,112 KB |
testcase_05 | AC | 91 ms
38,048 KB |
testcase_06 | AC | 78 ms
38,236 KB |
testcase_07 | AC | 82 ms
37,972 KB |
testcase_08 | AC | 87 ms
38,424 KB |
testcase_09 | AC | 105 ms
38,048 KB |
testcase_10 | AC | 119 ms
38,372 KB |
testcase_11 | AC | 99 ms
38,192 KB |
testcase_12 | AC | 90 ms
38,268 KB |
testcase_13 | AC | 74 ms
38,136 KB |
testcase_14 | AC | 115 ms
38,528 KB |
testcase_15 | AC | 138 ms
38,504 KB |
testcase_16 | AC | 130 ms
38,388 KB |
testcase_17 | AC | 136 ms
38,300 KB |
testcase_18 | AC | 82 ms
37,888 KB |
testcase_19 | AC | 138 ms
38,528 KB |
testcase_20 | AC | 64 ms
37,208 KB |
testcase_21 | AC | 56 ms
37,052 KB |
testcase_22 | AC | 114 ms
38,400 KB |
testcase_23 | AC | 138 ms
38,608 KB |
testcase_24 | AC | 138 ms
38,424 KB |
testcase_25 | AC | 137 ms
38,424 KB |
testcase_26 | AC | 56 ms
36,752 KB |
testcase_27 | AC | 77 ms
38,244 KB |
testcase_28 | AC | 127 ms
38,528 KB |
testcase_29 | AC | 99 ms
38,048 KB |
testcase_30 | AC | 54 ms
36,992 KB |
testcase_31 | AC | 56 ms
36,896 KB |
testcase_32 | AC | 95 ms
38,212 KB |
ソースコード
import java.io.InputStream; import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.Arrays; import java.util.StringTokenizer; public class Yuki3 { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Solver solver = new Solver(); solver.solve(1, in, out); out.close(); } static class Solver { final int INF = Integer.MAX_VALUE; public void solve(int testNumber, InputReader in, PrintWriter out) { n = in.nextInt(); moves = new int[n+1]; Arrays.fill(moves, INF); moves[1] = 1; dfs(1, 1); int ans = moves[n] == INF ? -1 : moves[n]; System.out.println(ans); } int n; int[] moves; public void dfs(int cur, int move) { int dist = Integer.bitCount(cur); int next = cur-dist; if (0 < next) { if (move+1 < moves[next]) { moves[next] = move+1; dfs(next, move+1); } } next = cur+dist; if (next <= n) { if (move+1 < moves[next]) { moves[next] = move+1; dfs(next, move+1); } } } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }