結果
問題 | No.3 ビットすごろく |
ユーザー | gemmaro |
提出日時 | 2020-05-22 12:01:31 |
言語 | Ruby (3.2.2) |
結果 |
AC
|
実行時間 | 90 ms / 5,000 ms |
コード長 | 797 bytes |
コンパイル時間 | 135 ms |
コンパイル使用メモリ | 11,296 KB |
実行使用メモリ | 16,828 KB |
最終ジャッジ日時 | 2023-09-14 01:43:56 |
合計ジャッジ時間 | 3,836 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 66 ms
15,320 KB |
testcase_01 | AC | 70 ms
15,148 KB |
testcase_02 | AC | 67 ms
15,204 KB |
testcase_03 | AC | 70 ms
15,640 KB |
testcase_04 | AC | 67 ms
15,064 KB |
testcase_05 | AC | 73 ms
16,064 KB |
testcase_06 | AC | 74 ms
15,624 KB |
testcase_07 | AC | 68 ms
15,392 KB |
testcase_08 | AC | 71 ms
15,748 KB |
testcase_09 | AC | 76 ms
16,244 KB |
testcase_10 | AC | 78 ms
16,520 KB |
testcase_11 | AC | 75 ms
16,028 KB |
testcase_12 | AC | 75 ms
16,088 KB |
testcase_13 | AC | 69 ms
15,496 KB |
testcase_14 | AC | 78 ms
16,360 KB |
testcase_15 | AC | 82 ms
16,584 KB |
testcase_16 | AC | 79 ms
16,636 KB |
testcase_17 | AC | 79 ms
16,828 KB |
testcase_18 | AC | 68 ms
15,320 KB |
testcase_19 | AC | 80 ms
16,824 KB |
testcase_20 | AC | 67 ms
15,128 KB |
testcase_21 | AC | 69 ms
15,028 KB |
testcase_22 | AC | 82 ms
16,356 KB |
testcase_23 | AC | 85 ms
16,620 KB |
testcase_24 | AC | 90 ms
16,796 KB |
testcase_25 | AC | 87 ms
16,660 KB |
testcase_26 | AC | 70 ms
15,156 KB |
testcase_27 | AC | 71 ms
15,404 KB |
testcase_28 | AC | 78 ms
16,608 KB |
testcase_29 | AC | 76 ms
16,036 KB |
testcase_30 | AC | 67 ms
15,060 KB |
testcase_31 | AC | 67 ms
15,036 KB |
testcase_32 | AC | 75 ms
16,124 KB |
コンパイルメッセージ
Syntax OK
ソースコード
# frozen_string_literal: true # rubocop:todo Metrics/AbcSize # rubocop:todo Metrics/CyclomaticComplexity def solve # rubocop:todo Metrics/MethodLength return 1 if N == 1 positions = [0] squares = Array.new(N, nil) squares[0] = 0 (1..N).each do |step| positions = positions.map do |position| bit_count = BIT_COUNTS[position + 1] return step + 1 if (position + bit_count) == N - 1 [position - bit_count, position + bit_count].map do |i| if i >= 0 && i <= N - 1 && (squares[i].nil? || step < squares[i]) squares[i] = step i end end.compact end.flatten end -1 end # rubocop:enable Metrics/CyclomaticComplexity # rubocop:enable Metrics/AbcSize N = gets.to_i BIT_COUNTS = (0..N).map { _1.digits(2).sum } puts solve