結果
問題 | No.1017 Reiwa Sequence |
ユーザー | tamato |
提出日時 | 2020-04-03 23:22:01 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,840 bytes |
コンパイル時間 | 281 ms |
コンパイル使用メモリ | 86,912 KB |
実行使用メモリ | 833,572 KB |
最終ジャッジ日時 | 2023-09-16 04:54:46 |
合計ジャッジ時間 | 19,635 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 78 ms
81,948 KB |
testcase_01 | AC | 85 ms
77,808 KB |
testcase_02 | AC | 77 ms
77,936 KB |
testcase_03 | AC | 84 ms
78,216 KB |
testcase_04 | AC | 82 ms
78,760 KB |
testcase_05 | AC | 113 ms
94,688 KB |
testcase_06 | AC | 100 ms
86,500 KB |
testcase_07 | AC | 82 ms
78,328 KB |
testcase_08 | AC | 81 ms
78,176 KB |
testcase_09 | AC | 369 ms
228,524 KB |
testcase_10 | AC | 1,253 ms
455,056 KB |
testcase_11 | AC | 715 ms
289,052 KB |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | AC | 293 ms
186,988 KB |
testcase_15 | AC | 398 ms
242,060 KB |
testcase_16 | AC | 707 ms
286,656 KB |
testcase_17 | AC | 1,208 ms
411,308 KB |
testcase_18 | AC | 398 ms
247,652 KB |
testcase_19 | MLE | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
ソースコード
def main(): import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) ans = [0] * N seen = [[] for _ in range(300010)] 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] S = sum(A) if not ok: dp = [[False] * (2*S+10) for _ in range(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 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()