結果

問題 No.1017 Reiwa Sequence
ユーザー Mao-betaMao-beta
提出日時 2024-03-12 12:18:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 1,864 bytes
コンパイル時間 237 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 168,780 KB
最終ジャッジ日時 2024-03-12 12:19:27
合計ジャッジ時間 38,911 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
57,704 KB
testcase_01 AC 43 ms
57,704 KB
testcase_02 AC 42 ms
57,704 KB
testcase_03 AC 49 ms
63,412 KB
testcase_04 AC 43 ms
57,704 KB
testcase_05 AC 43 ms
57,704 KB
testcase_06 AC 43 ms
57,704 KB
testcase_07 AC 42 ms
57,704 KB
testcase_08 AC 43 ms
57,704 KB
testcase_09 AC 50 ms
64,176 KB
testcase_10 AC 52 ms
70,352 KB
testcase_11 AC 48 ms
64,184 KB
testcase_12 AC 67 ms
99,024 KB
testcase_13 AC 59 ms
96,948 KB
testcase_14 AC 48 ms
64,184 KB
testcase_15 AC 49 ms
66,252 KB
testcase_16 AC 50 ms
64,184 KB
testcase_17 AC 53 ms
69,572 KB
testcase_18 AC 49 ms
64,184 KB
testcase_19 AC 245 ms
119,376 KB
testcase_20 AC 223 ms
119,380 KB
testcase_21 AC 217 ms
119,380 KB
testcase_22 AC 214 ms
119,380 KB
testcase_23 AC 219 ms
119,380 KB
testcase_24 AC 219 ms
119,380 KB
testcase_25 AC 216 ms
119,376 KB
testcase_26 AC 236 ms
119,380 KB
testcase_27 AC 169 ms
109,520 KB
testcase_28 AC 191 ms
113,380 KB
testcase_29 AC 59 ms
73,160 KB
testcase_30 AC 62 ms
76,860 KB
testcase_31 AC 78 ms
87,024 KB
testcase_32 AC 152 ms
100,444 KB
testcase_33 AC 52 ms
70,480 KB
testcase_34 AC 45 ms
57,704 KB
testcase_35 AC 43 ms
57,704 KB
testcase_36 AC 47 ms
57,704 KB
testcase_37 AC 140 ms
100,444 KB
testcase_38 AC 48 ms
61,776 KB
testcase_39 AC 143 ms
100,444 KB
testcase_40 AC 304 ms
166,380 KB
testcase_41 AC 299 ms
166,372 KB
testcase_42 AC 314 ms
168,744 KB
testcase_43 AC 285 ms
168,684 KB
testcase_44 AC 127 ms
140,356 KB
testcase_45 AC 285 ms
166,332 KB
testcase_46 AC 289 ms
168,780 KB
testcase_47 AC 287 ms
168,748 KB
testcase_48 AC 166 ms
110,148 KB
testcase_49 AC 150 ms
150,472 KB
testcase_50 AC 105 ms
99,784 KB
testcase_51 AC 42 ms
57,704 KB
testcase_52 AC 216 ms
119,252 KB
testcase_53 AC 101 ms
95,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
import bisect
from heapq import heapify, heappop, heappush
from collections import deque, defaultdict, Counter
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD99 = 998244353

input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
SMI = lambda: input().split()
SLI = lambda: list(SMI())
EI = lambda m: [NLI() for _ in range(m)]


def main():
    N = NI()
    A = NLI()
    C = Counter(A)
    MC = C.most_common()
    if MC[0][1] >= 2:
        x = MC[0][0]
        ans = []
        cnt = 0
        for a in A:
            if a == x:
                if cnt == 0:
                    ans.append(a)
                elif cnt == 1:
                    ans.append(-a)
                else:
                    ans.append(0)
                cnt += 1
            else:
                ans.append(0)
        print("Yes")
        print(*ans)

    else:
        B = min(N, 22)
        S = set()
        T = [0] * (1<<B)
        c = -1
        d = 0
        for case in range(1<<B):
            tmp = 0
            for i in range(B):
                if (case >> i) & 1:
                    tmp += A[i]
            if tmp in S:
                c = T.index(tmp)
                d = case
                break
            else:
                S.add(tmp)
                T[case] = tmp

        if c == -1:
            print("No")
            return

        ans = []
        for i, a in enumerate(A):
            if (c>>i) & 1:
                ans.append(a)
            elif (d>>i) & 1:
                ans.append(-a)
            else:
                ans.append(0)

        print("Yes")
        print(*ans)


if __name__ == "__main__":
    main()
0