結果

問題 No.1017 Reiwa Sequence
ユーザー shotoyooshotoyoo
提出日時 2021-05-09 11:59:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 614 ms / 2,000 ms
コード長 1,238 bytes
コンパイル時間 457 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 278,980 KB
最終ジャッジ日時 2023-10-18 22:12:25
合計ジャッジ時間 42,847 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,384 KB
testcase_01 AC 38 ms
53,408 KB
testcase_02 AC 38 ms
53,408 KB
testcase_03 AC 39 ms
53,408 KB
testcase_04 AC 38 ms
53,408 KB
testcase_05 AC 39 ms
53,408 KB
testcase_06 AC 38 ms
53,408 KB
testcase_07 AC 39 ms
53,408 KB
testcase_08 AC 38 ms
53,408 KB
testcase_09 AC 47 ms
59,776 KB
testcase_10 AC 49 ms
64,184 KB
testcase_11 AC 45 ms
59,776 KB
testcase_12 AC 50 ms
66,232 KB
testcase_13 AC 41 ms
53,408 KB
testcase_14 AC 43 ms
59,564 KB
testcase_15 AC 43 ms
59,564 KB
testcase_16 AC 44 ms
59,564 KB
testcase_17 AC 45 ms
63,112 KB
testcase_18 AC 44 ms
59,564 KB
testcase_19 AC 260 ms
223,656 KB
testcase_20 AC 235 ms
223,564 KB
testcase_21 AC 238 ms
223,708 KB
testcase_22 AC 252 ms
223,708 KB
testcase_23 AC 241 ms
223,708 KB
testcase_24 AC 242 ms
223,708 KB
testcase_25 AC 241 ms
223,708 KB
testcase_26 AC 226 ms
223,708 KB
testcase_27 AC 333 ms
237,148 KB
testcase_28 AC 352 ms
241,096 KB
testcase_29 AC 52 ms
70,496 KB
testcase_30 AC 61 ms
78,316 KB
testcase_31 AC 107 ms
107,444 KB
testcase_32 AC 306 ms
225,464 KB
testcase_33 AC 52 ms
67,744 KB
testcase_34 AC 309 ms
218,640 KB
testcase_35 AC 38 ms
53,408 KB
testcase_36 AC 38 ms
53,408 KB
testcase_37 AC 305 ms
226,080 KB
testcase_38 AC 38 ms
53,408 KB
testcase_39 AC 315 ms
228,584 KB
testcase_40 AC 614 ms
278,980 KB
testcase_41 AC 579 ms
265,788 KB
testcase_42 AC 579 ms
265,200 KB
testcase_43 AC 577 ms
264,840 KB
testcase_44 AC 65 ms
84,780 KB
testcase_45 AC 573 ms
265,188 KB
testcase_46 AC 564 ms
265,244 KB
testcase_47 AC 533 ms
265,204 KB
testcase_48 AC 90 ms
100,316 KB
testcase_49 AC 80 ms
98,800 KB
testcase_50 AC 84 ms
99,752 KB
testcase_51 AC 39 ms
53,408 KB
testcase_52 AC 398 ms
248,952 KB
testcase_53 AC 164 ms
141,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
for v in a:
    if v in s:
        val = v
        done = 1
        break
    ns = set()
    for vv in s:
        if v+vv in s:
            val = v+vv
            done = 1
            break
        ns.add(v+vv)
    s |= ns
    if done:
        break
if not done:
    print("No")
else:
    print("Yes")
    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==val:
                index = get(vv)
                index.append(i)
                res.append(index)
            nd[v+vv] = i
        d.update(nd)
        if len(res)>=2:
            break
    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)))
0