結果

問題 No.2890 Chiffon
ユーザー adapchiadapchi
提出日時 2024-09-13 22:32:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 661 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 118,888 KB
最終ジャッジ日時 2024-09-26 14:41:11
合計ジャッジ時間 4,596 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 53
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, input().split())
A = [(int(x) - 1) // 2 for x in input().split()]
A.append(A[0] + N)

def check2(x, y, last):
  pos = A[0] - y
  for i in range(K):
    if (i < K - 1 or last) and pos + x >= (A[i + 1] if i < K - 1 else A[K] - y + 1):
      return False
    pos = max(A[i], pos + x)
  return True

def check(x):
  d = A[K] - A[K - 1]
  ng = 0
  ok = d + 1
  while ok - ng > 1:
    mid = (ok + ng) // 2
    if check2(x, mid, False):
      ok = mid
    else:
      ng = mid
  return ok <= d and check2(x, ok, True)

ok = 1
ng = 10 ** 18

while ng - ok > 1:
  mid = (ok + ng) // 2
  if check(mid):
    ok = mid
  else:
    ng = mid
    
print(ok * 2)
0