結果

問題 No.451 575
ユーザー mkawa2mkawa2
提出日時 2020-04-25 21:45:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 2,016 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 20,096 KB
最終ジャッジ日時 2024-04-25 11:00:11
合計ジャッジ時間 4,635 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,752 KB
testcase_01 AC 28 ms
10,880 KB
testcase_02 AC 28 ms
10,880 KB
testcase_03 AC 27 ms
10,880 KB
testcase_04 AC 28 ms
10,752 KB
testcase_05 AC 31 ms
11,392 KB
testcase_06 AC 43 ms
12,544 KB
testcase_07 AC 110 ms
20,096 KB
testcase_08 AC 28 ms
10,752 KB
testcase_09 AC 30 ms
10,880 KB
testcase_10 AC 67 ms
12,800 KB
testcase_11 AC 148 ms
16,768 KB
testcase_12 AC 187 ms
18,688 KB
testcase_13 AC 187 ms
18,816 KB
testcase_14 AC 27 ms
10,880 KB
testcase_15 AC 31 ms
11,136 KB
testcase_16 AC 41 ms
12,160 KB
testcase_17 AC 109 ms
18,816 KB
testcase_18 AC 112 ms
18,688 KB
testcase_19 AC 82 ms
16,128 KB
testcase_20 AC 35 ms
11,264 KB
testcase_21 AC 30 ms
11,008 KB
testcase_22 AC 28 ms
10,752 KB
testcase_23 AC 192 ms
19,328 KB
testcase_24 AC 119 ms
14,592 KB
testcase_25 AC 27 ms
10,880 KB
testcase_26 AC 29 ms
10,880 KB
testcase_27 AC 29 ms
10,880 KB
testcase_28 AC 29 ms
10,880 KB
testcase_29 AC 36 ms
11,520 KB
testcase_30 AC 109 ms
19,584 KB
testcase_31 AC 27 ms
10,752 KB
testcase_32 AC 59 ms
14,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    inf = float("inf")
    n = II()
    bb = [II() for _ in range(n)]
    aa = [0]
    # 仮にaの初項を0としてシミュレーションする
    for i, b in enumerate(bb):
        if i % 2: aa.append(-b + aa[-1])
        else: aa.append(b - aa[-1])
    # print(aa)
    # 0-indexedで考える
    # ここから答えの数列を作るには、初項をa0とすると
    # i%4==0,3のaa[i]にはa0を足す
    # i%4==1,2のaa[i]には-a0を足すとできる
    # このとき、各項が1<=aa[i]<=10**18となるようにa0を決める
    # インデックスのmod4が0,3の項の最大値と1,2の項の最小値を求める
    max03 = max12 = -inf
    min03 = min12 = inf
    for i, a in enumerate(aa):
        if i % 4 == 0 or i % 4 == 3:
            if a > max03: max03 = a
            if a < min03: min03 = a
        else:
            if a < min12: min12 = a
            if a < min12: min12 = a
    # a0の範囲を求める
    l = max(1 - min03, max12 - 10 ** 18, 1)
    r = min(10 ** 18 - max03, min12 - 1, 10 ** 18)
    # [l,r]の範囲が存在しないときは解なし
    if l > r:
        print(-1)
        exit()
    # [l,r]ならいくつでもよいが、今回はa0=lとして前述の方法で復元する
    print(n + 1)
    for i, a in enumerate(aa):
        if i % 4 == 0 or i % 4 == 3:
            print(a + l)
        else:
            print(a - l)

main()
0