結果

問題 No.1884 Sequence
ユーザー kohei2019kohei2019
提出日時 2023-07-08 15:49:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 284 ms / 2,000 ms
コード長 805 bytes
コンパイル時間 355 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 136,376 KB
最終ジャッジ日時 2023-09-29 17:09:20
合計ジャッジ時間 10,413 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
71,804 KB
testcase_01 AC 88 ms
71,672 KB
testcase_02 AC 89 ms
71,344 KB
testcase_03 AC 90 ms
71,576 KB
testcase_04 AC 88 ms
71,812 KB
testcase_05 AC 89 ms
71,704 KB
testcase_06 AC 88 ms
71,824 KB
testcase_07 AC 87 ms
71,764 KB
testcase_08 AC 89 ms
71,820 KB
testcase_09 AC 90 ms
71,344 KB
testcase_10 AC 284 ms
126,488 KB
testcase_11 AC 283 ms
126,764 KB
testcase_12 AC 126 ms
98,924 KB
testcase_13 AC 123 ms
102,084 KB
testcase_14 AC 127 ms
99,500 KB
testcase_15 AC 191 ms
133,444 KB
testcase_16 AC 237 ms
127,700 KB
testcase_17 AC 155 ms
121,488 KB
testcase_18 AC 182 ms
136,376 KB
testcase_19 AC 170 ms
125,364 KB
testcase_20 AC 177 ms
127,340 KB
testcase_21 AC 157 ms
117,780 KB
testcase_22 AC 186 ms
130,368 KB
testcase_23 AC 230 ms
125,384 KB
testcase_24 AC 227 ms
130,204 KB
testcase_25 AC 225 ms
127,184 KB
testcase_26 AC 232 ms
131,996 KB
testcase_27 AC 123 ms
105,408 KB
testcase_28 AC 123 ms
105,432 KB
testcase_29 AC 122 ms
105,212 KB
testcase_30 AC 125 ms
105,672 KB
testcase_31 AC 164 ms
122,220 KB
testcase_32 AC 225 ms
127,572 KB
testcase_33 AC 160 ms
127,096 KB
testcase_34 AC 158 ms
127,148 KB
testcase_35 AC 128 ms
106,360 KB
testcase_36 AC 150 ms
119,036 KB
testcase_37 AC 158 ms
127,472 KB
testcase_38 AC 155 ms
125,952 KB
testcase_39 AC 143 ms
109,028 KB
testcase_40 AC 137 ms
110,360 KB
testcase_41 AC 207 ms
126,164 KB
testcase_42 AC 213 ms
124,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
import collections
N=int(input())
lsA = list(map(int,input().split()))
cnt0 = 0
lsA1 = []
for i in range(N):
    if lsA[i] == 0:
        cnt0 += 1
    else:
        lsA1.append(lsA[i])
lsA1.sort()
if len(lsA1) == 0:
    print('Yes')
    exit()

cnt = collections.Counter(lsA1)
if len(cnt)==1:
    print('Yes')
    exit()

vals = max(list(cnt.values()))
if vals > 1:
    print('No')
    exit()

gcd = lsA1[1]-lsA1[0]
for i in range(1,len(lsA1)-1):
    gcd = math.gcd(lsA1[i+1]-lsA1[i],gcd)

lsA1.reverse()
st = lsA1.pop()
for i in range(N-1):
    if not lsA1:
        print('Yes')
        exit()
    if lsA1[-1] == st+gcd:
        st = lsA1.pop()
    else:
        if cnt0 == 0:
            print('No')
            exit()
        else:
            cnt0 -= 1
            st = st+gcd
print('Yes')
0