結果
問題 |
No.2071 Shift and OR
|
ユーザー |
![]() |
提出日時 | 2022-09-18 14:02:02 |
言語 | Ruby (3.4.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 399 bytes |
コンパイル時間 | 82 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 26,368 KB |
最終ジャッジ日時 | 2024-12-22 01:17:02 |
合計ジャッジ時間 | 7,136 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 WA * 2 |
コンパイルメッセージ
Syntax OK
ソースコード
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]