結果

問題 No.2071 Shift and OR
ユーザー simansiman
提出日時 2022-09-18 18:48:59
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,804 ms / 2,000 ms
コード長 412 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 11,348 KB
実行使用メモリ 27,792 KB
最終ジャッジ日時 2023-08-23 18:16:45
合計ジャッジ時間 23,890 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
17,092 KB
testcase_01 AC 103 ms
17,404 KB
testcase_02 AC 144 ms
18,460 KB
testcase_03 AC 584 ms
19,516 KB
testcase_04 AC 284 ms
19,204 KB
testcase_05 AC 1,088 ms
21,064 KB
testcase_06 AC 366 ms
19,004 KB
testcase_07 AC 177 ms
18,380 KB
testcase_08 AC 244 ms
19,036 KB
testcase_09 AC 323 ms
19,124 KB
testcase_10 AC 381 ms
19,000 KB
testcase_11 AC 1,239 ms
21,532 KB
testcase_12 AC 1,264 ms
21,604 KB
testcase_13 AC 1,010 ms
21,012 KB
testcase_14 AC 92 ms
16,440 KB
testcase_15 AC 744 ms
20,016 KB
testcase_16 AC 738 ms
20,068 KB
testcase_17 AC 1,199 ms
21,488 KB
testcase_18 AC 98 ms
17,612 KB
testcase_19 AC 1,552 ms
22,116 KB
testcase_20 AC 1,276 ms
22,132 KB
testcase_21 AC 1,804 ms
23,656 KB
testcase_22 AC 1,573 ms
22,764 KB
testcase_23 AC 143 ms
26,640 KB
testcase_24 AC 83 ms
16,048 KB
testcase_25 AC 106 ms
20,640 KB
testcase_26 AC 117 ms
21,652 KB
testcase_27 AC 79 ms
15,284 KB
testcase_28 AC 147 ms
27,792 KB
testcase_29 AC 149 ms
27,640 KB
testcase_30 AC 617 ms
19,528 KB
testcase_31 AC 299 ms
19,528 KB
testcase_32 AC 303 ms
19,652 KB
testcase_33 AC 343 ms
19,540 KB
testcase_34 AC 425 ms
19,548 KB
testcase_35 AC 457 ms
19,460 KB
testcase_36 AC 609 ms
19,388 KB
testcase_37 AC 388 ms
19,720 KB
testcase_38 AC 341 ms
19,392 KB
testcase_39 AC 307 ms
19,460 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
A = gets.split.map(&:to_i)

def shift(x)
  x / 2 + 2 ** 15 * (x % 2)
end

if N >= 16
  puts 2 ** 16 - 1
  exit
end

L = 2 ** 16 
dp = Array.new(N + 1) { Array.new(L, false) }
dp[0][0] = true

1.upto(N) do |i|
  L.times do |j|
    next if not dp[i - 1][j]
    a = A[i - 1]

    16.times do
      nv = j | a
      dp[i][nv] |= dp[i - 1][j]
      a = shift(a)
    end
  end
end

pp dp[N].rindex(true)
0