結果
問題 | No.3 ビットすごろく |
ユーザー | WagiHOH |
提出日時 | 2016-07-08 10:58:37 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 57 ms / 5,000 ms |
コード長 | 1,157 bytes |
コンパイル時間 | 588 ms |
コンパイル使用メモリ | 84,248 KB |
実行使用メモリ | 7,792 KB |
最終ジャッジ日時 | 2023-09-02 21:19:36 |
合計ジャッジ時間 | 2,698 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,368 KB |
testcase_01 | AC | 2 ms
4,368 KB |
testcase_02 | AC | 1 ms
4,368 KB |
testcase_03 | AC | 7 ms
4,372 KB |
testcase_04 | AC | 3 ms
4,368 KB |
testcase_05 | AC | 20 ms
7,716 KB |
testcase_06 | AC | 7 ms
6,144 KB |
testcase_07 | AC | 5 ms
4,368 KB |
testcase_08 | AC | 16 ms
7,792 KB |
testcase_09 | AC | 29 ms
7,768 KB |
testcase_10 | AC | 49 ms
7,728 KB |
testcase_11 | AC | 27 ms
7,756 KB |
testcase_12 | AC | 19 ms
7,732 KB |
testcase_13 | AC | 6 ms
4,368 KB |
testcase_14 | AC | 44 ms
7,716 KB |
testcase_15 | AC | 55 ms
7,712 KB |
testcase_16 | AC | 53 ms
7,740 KB |
testcase_17 | AC | 56 ms
7,708 KB |
testcase_18 | AC | 5 ms
4,372 KB |
testcase_19 | AC | 57 ms
7,744 KB |
testcase_20 | AC | 3 ms
4,372 KB |
testcase_21 | AC | 2 ms
4,368 KB |
testcase_22 | AC | 46 ms
7,716 KB |
testcase_23 | AC | 57 ms
7,728 KB |
testcase_24 | AC | 57 ms
7,716 KB |
testcase_25 | AC | 56 ms
7,744 KB |
testcase_26 | AC | 1 ms
4,368 KB |
testcase_27 | AC | 6 ms
4,368 KB |
testcase_28 | AC | 52 ms
7,716 KB |
testcase_29 | AC | 29 ms
7,752 KB |
testcase_30 | AC | 1 ms
4,368 KB |
testcase_31 | AC | 2 ms
4,368 KB |
testcase_32 | AC | 23 ms
7,720 KB |
ソースコード
import std.stdio; import std.string; import std.conv; import std.algorithm; import std.range; import core.bitop; struct Block { uint bits; bool forward, backward; uint optimum = uint.max; } void main() { immutable n = readln.chomp.to!uint; auto game = new Block[n + 1]; foreach (i, ref x; game) x.bits = popcnt(cast(uint)i); uint[] route = [1]; do { auto point = route.back; if (point < 1 || point > n) { route.popBack; continue; } with (game[point]) { if (optimum > route.length) { optimum = cast(uint)route.length; forward = backward = false; } if (optimum < route.length) { route.popBack; continue; } if (!forward) { route ~= point + bits; forward = true; } else if (!backward) { route ~= point - bits; backward = true; } else { route.popBack; } } } while (!route.empty); writeln(cast(int)game[n].optimum); }