結果
| 問題 |
No.3219 Ruler to Maximize
|
| ユーザー |
|
| 提出日時 | 2025-08-03 17:59:06 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 971 bytes |
| コンパイル時間 | 320 ms |
| コンパイル使用メモリ | 82,784 KB |
| 実行使用メモリ | 61,060 KB |
| 最終ジャッジ日時 | 2025-08-03 17:59:11 |
| 合計ジャッジ時間 | 4,517 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 WA * 12 |
ソースコード
from collections import deque
N = int(input())
A = list(map(int, input().split()))
que = deque([(0, 0, 0, "")]) # (w, b, i, s)
visited = set()
visited.add((0, 0, 0)) # (w, b, i)
results = [] # N個割り当てたものを保存
while que:
w, b, i, s = que.popleft()
if i == N:
results.append((w, b, s))
continue
a = A[i]
# 黒に割り当て
if (w & a) == 0:
w2, b2, i2, s2 = w, b | a, i + 1, s + "B"
key = (w2, b2, i2)
if key not in visited:
visited.add(key)
que.append((w2, b2, i2, s2))
# 白に割り当て
if (b & a) == 0:
w2, b2, i2, s2 = w | a, b, i + 1, s + "W"
key = (w2, b2, i2)
if key not in visited:
visited.add(key)
que.append((w2, b2, i2, s2))
# N個割り当てたものの中で最大値
m = 0
ans = ""
for w, b, s in results:
if w * b > m:
m = w * b
ans = s
print(m)
print(ans)