結果
問題 |
No.3219 Ruler to Maximize
|
ユーザー |
|
提出日時 | 2025-08-03 17:56:32 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 972 bytes |
コンパイル時間 | 218 ms |
コンパイル使用メモリ | 82,656 KB |
実行使用メモリ | 61,768 KB |
最終ジャッジ日時 | 2025-08-03 17:56:38 |
合計ジャッジ時間 | 4,484 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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) while que: if que[0][2] == N: # 末端はそのまま、あとで全部調べる break w,b,i,s = que.popleft() 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 = "" # i==Nのもののみ考慮 for w, b, i, s in que: if w * b > m: m = w * b ans = s print(m) print(ans)