結果
問題 | No.1017 Reiwa Sequence |
ユーザー |
|
提出日時 | 2024-10-08 23:04:12 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,161 bytes |
コンパイル時間 | 333 ms |
コンパイル使用メモリ | 82,308 KB |
実行使用メモリ | 114,684 KB |
最終ジャッジ日時 | 2024-10-08 23:04:55 |
合計ジャッジ時間 | 38,956 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 45 WA * 5 |
ソースコード
N = int(input())A = list(map(int, input().split()))M = 150001exist = [-1] * Mfor i, ai in enumerate(A):if exist[ai] != -1:ans = [0] * Nans[i] = -aians[exist[ai]] = aiprint('Yes')print(*ans)quit()exist[ai] = iorder = sorted(range(N), key=lambda i:A[i])dp = [[0]*2*M]dp[0][0] = 1for pos, i in enumerate(order):ai = A[i]if dp[-1][ai]:print('Yes')ans = [0] * Nans[i] = -ainow = aifor ii in order[:pos][::-1]:dp.pop()aii = A[ii]if dp[-1][now]:continueif -M+1 <= now - aii and dp[-1][now-aii]:now -= aiians[ii] = aiicontinueif now + aii < M and dp[-1][now+aii]:now += aiians[ii] = -aiiprint(*ans)quit()nex = [0] * 2*Mfor j in range(-M+1, M):nex[j] |= dp[-1][j]if dp[-1][j]:if -M+1 <= j-ai:nex[j-ai] = 1if j+ai < M:nex[j+ai] = 1dp.append(nex)print('No')