結果

問題 No.2890 Chiffon
ユーザー 👑 seekworser
提出日時 2024-07-05 14:35:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 708 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 155,020 KB
最終ジャッジ日時 2024-09-26 14:32:41
合計ジャッジ時間 6,590 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 53
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k = map(int, input().split())
a = list(map(int, input().split()))
a.append(a[0] + 2*n)

p = 0
mn = 2*n
for i in range(k):
    if mn > a[i+1] - a[i]:
        p = i
        mn = a[i+1] - a[i]

an = [0] * (k)
for i in range(k):
    an[i] = (a[(p+i) % k] - a[p]) % (2*n)
an.append(2*n)

ans = 0
for s in range(1, an[1], 2):
    ok = 0
    ng = n
    while ng - ok > 1:
        mid = (ok + ng) // 2
        def check():
            x = 2*mid
            si = s
            for i in range(k-1):
                if si + x > an[i+2]: return False
                si = max(si+x, an[i+1]+1)
            return si + x <= s + 2*n
        if check(): ok = mid
        else: ng = mid
    ans = max(ans, ok*2)
print(ans)
0