結果
問題 |
No.1017 Reiwa Sequence
|
ユーザー |
|
提出日時 | 2021-05-09 12:06:45 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,155 ms / 2,000 ms |
コード長 | 981 bytes |
コンパイル時間 | 226 ms |
コンパイル使用メモリ | 82,392 KB |
実行使用メモリ | 346,224 KB |
最終ジャッジ日時 | 2024-09-18 18:19:54 |
合計ジャッジ時間 | 42,511 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 50 |
ソースコード
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(2*10**5+10) write = lambda x: sys.stdout.write(x+"\n") debug = lambda x: sys.stderr.write(x+"\n") writef = lambda x: print("{:.12f}".format(x)) n = int(input()) a = list(map(int, input().split())) s = set([0]) done = 0 d = {0: None} res = [] def get(v): assert v in d index = [] while d[v] is not None: ind = d[v] index.append(ind) v -= a[ind] return index for i,v in enumerate(a): nd = {} for vv in d: if v+vv in d: index0 = get(v+vv) index = get(vv) index.append(i) res.append(index) res.append(index0) nd[v+vv] = i d.update(nd) if len(res)>=2: print("Yes") ans = [0]*n for i in res[0]: ans[i] += a[i] for i in res[1]: ans[i] -= a[i] write(" ".join(map(str, ans))) break else: print("No")