結果

問題 No.2071 Shift and OR
ユーザー simansiman
提出日時 2022-09-18 14:02:02
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 399 bytes
コンパイル時間 436 ms
コンパイル使用メモリ 11,400 KB
実行使用メモリ 27,840 KB
最終ジャッジ日時 2023-08-23 18:08:23
合計ジャッジ時間 7,808 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
15,392 KB
testcase_01 AC 87 ms
15,300 KB
testcase_02 AC 86 ms
15,620 KB
testcase_03 AC 87 ms
15,416 KB
testcase_04 WA -
testcase_05 AC 102 ms
15,440 KB
testcase_06 AC 86 ms
15,540 KB
testcase_07 AC 86 ms
15,424 KB
testcase_08 AC 86 ms
15,436 KB
testcase_09 AC 87 ms
15,508 KB
testcase_10 AC 88 ms
15,572 KB
testcase_11 AC 122 ms
15,532 KB
testcase_12 AC 126 ms
15,620 KB
testcase_13 AC 104 ms
15,328 KB
testcase_14 AC 85 ms
15,376 KB
testcase_15 AC 89 ms
15,336 KB
testcase_16 AC 87 ms
15,524 KB
testcase_17 AC 121 ms
15,360 KB
testcase_18 AC 85 ms
15,288 KB
testcase_19 AC 169 ms
15,448 KB
testcase_20 AC 171 ms
15,464 KB
testcase_21 AC 915 ms
15,596 KB
testcase_22 AC 269 ms
15,640 KB
testcase_23 AC 150 ms
26,856 KB
testcase_24 AC 89 ms
16,052 KB
testcase_25 AC 108 ms
20,544 KB
testcase_26 AC 122 ms
21,676 KB
testcase_27 AC 82 ms
15,060 KB
testcase_28 AC 151 ms
27,840 KB
testcase_29 AC 151 ms
27,812 KB
testcase_30 AC 87 ms
15,292 KB
testcase_31 AC 87 ms
15,396 KB
testcase_32 AC 85 ms
15,428 KB
testcase_33 AC 86 ms
15,588 KB
testcase_34 AC 87 ms
15,380 KB
testcase_35 AC 87 ms
15,336 KB
testcase_36 AC 87 ms
15,388 KB
testcase_37 AC 86 ms
15,364 KB
testcase_38 AC 85 ms
15,336 KB
testcase_39 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 ** N
dp = Array.new(L, 0)

L.times do |mask|
  N.times do |i|
    next if mask[i] != 0
    nmask = mask | (1 << i)
    a = A[i]

    16.times do |j|
      a = shift(a)
      nv = dp[mask] | a
      dp[nmask] = nv if dp[nmask] < nv
    end
  end
end

pp dp[L - 1]
0