結果
問題 |
No.1017 Reiwa Sequence
|
ユーザー |
|
提出日時 | 2024-10-08 23:21:08 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 930 bytes |
コンパイル時間 | 373 ms |
コンパイル使用メモリ | 82,292 KB |
実行使用メモリ | 545,912 KB |
最終ジャッジ日時 | 2024-10-08 23:21:28 |
合計ジャッジ時間 | 18,752 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 15 MLE * 1 -- * 34 |
ソースコード
N = int(input()) A = list(map(int, input().split())) M = 150001 exist = [-1] * M for i, ai in enumerate(A): if exist[ai] != -1: ans = [0] * N ans[i] = -ai ans[exist[ai]] = ai print('Yes') print(*ans) quit() exist[ai] = i order = sorted(range(N), key=lambda i:A[i]) dp = [{0}] for pos, i in enumerate(order): ai = A[i] if ai in dp[-1]: ans = [0] * N ans[i] = -ai now = ai for ii in order[:pos][::-1]: dp.pop() aii = A[ii] if now-aii in dp[-1]: now -= aii ans[ii] = aii elif now+aii in dp[-1]: now += aii ans[ii] = -aii print('Yes') print(*ans) quit() nex = set() for s in dp[-1]: nex.add(s) nex.add(s - ai) nex.add(s + ai) dp.append(nex) print('No')