結果
問題 | No.1017 Reiwa Sequence |
ユーザー | tamato |
提出日時 | 2020-04-03 23:10:35 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,431 bytes |
コンパイル時間 | 252 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 105,732 KB |
最終ジャッジ日時 | 2024-07-03 05:52:56 |
合計ジャッジ時間 | 32,240 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
62,080 KB |
testcase_01 | AC | 53 ms
64,640 KB |
testcase_02 | AC | 51 ms
63,232 KB |
testcase_03 | AC | 56 ms
68,096 KB |
testcase_04 | AC | 47 ms
63,232 KB |
testcase_05 | RE | - |
testcase_06 | AC | 50 ms
62,080 KB |
testcase_07 | AC | 47 ms
63,232 KB |
testcase_08 | AC | 47 ms
63,488 KB |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
testcase_45 | RE | - |
testcase_46 | RE | - |
testcase_47 | RE | - |
testcase_48 | RE | - |
testcase_49 | RE | - |
testcase_50 | RE | - |
testcase_51 | AC | 59 ms
68,688 KB |
testcase_52 | RE | - |
testcase_53 | RE | - |
ソースコード
def main(): import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) ans = [0] * N seen = [[] for _ in range(150001)] flg = 0 ok = 0 for i in range(N): if flg: break for j in range(i+1, N): if seen[A[i]+A[j]]: k, l = seen[A[i]+A[j]] ans[i] = 1 ans[j] = 1 ans[k] = -1 ans[l] = -1 flg = 1 ok = 1 break else: seen[A[i]+A[j]] = [i, j] if not ok: for i in range(N): if seen[A[i]]: j, k = seen[A[i]] ans[i] = 1 ans[j] = -1 ans[k] = -1 ok = 1 break if not ok: seen2 = [-1] * 150001 for i in range(N): if seen2[A[i]] != -1: j = seen2[A[i]] ans[i] = 1 ans[j] = -1 ok = 1 break else: seen2[A[i]] = i S = sum(A) if not ok: dp = [[False] * (2*S+1) for _ in range(2*N+1)] dp[0][0] = True for i, a in enumerate(A): for j in range(S+1): if dp[i][j]: dp[i+1][j+a] = True dp[i+1][j-a] = True if i==0 and j==0: continue dp[i+1][j] = True for j in range(-1, -S-1, -1): if dp[i][j]: dp[i+1][j+a] = True dp[i+1][j-a] = True if i==0 and j==0: continue dp[i+1][j] = True if dp[i+1][0]: idx = i ok = 1 break if ok: j = 0 for i in range(idx, -1, -1): if j-A[i] >= -S: if dp[i][j-A[i]]: j = j - A[i] ans[i] = 1 continue if j+A[i] <= S: if dp[i][j+A[i]]: j = j + A[i] ans[i] = -1 for i in range(N): ans[i] *= A[i] if ok: print('Yes') print(*ans) else: print('No') if __name__ == '__main__': main()