結果

問題 No.484 収穫
ユーザー mkawa2mkawa2
提出日時 2023-04-19 15:01:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,286 ms / 3,000 ms
コード長 1,508 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 82,356 KB
実行使用メモリ 244,612 KB
最終ジャッジ日時 2024-04-22 15:54:36
合計ジャッジ時間 17,671 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,736 KB
testcase_01 AC 38 ms
53,120 KB
testcase_02 AC 38 ms
52,864 KB
testcase_03 AC 38 ms
53,120 KB
testcase_04 AC 37 ms
53,120 KB
testcase_05 AC 43 ms
53,248 KB
testcase_06 AC 41 ms
53,760 KB
testcase_07 AC 39 ms
53,248 KB
testcase_08 AC 41 ms
53,376 KB
testcase_09 AC 65 ms
70,016 KB
testcase_10 AC 90 ms
77,056 KB
testcase_11 AC 59 ms
67,712 KB
testcase_12 AC 1,391 ms
193,244 KB
testcase_13 AC 2,150 ms
238,008 KB
testcase_14 AC 1,555 ms
202,376 KB
testcase_15 AC 1,715 ms
209,424 KB
testcase_16 AC 2,286 ms
244,612 KB
testcase_17 AC 140 ms
140,032 KB
testcase_18 AC 138 ms
140,288 KB
testcase_19 AC 1,394 ms
153,688 KB
testcase_20 AC 1,350 ms
154,500 KB
testcase_21 AC 1,383 ms
153,360 KB
testcase_22 AC 2,005 ms
224,552 KB
testcase_23 AC 162 ms
140,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# md = 10**9+7
md = 998244353

from heapq import *

def pack(l,r,s):
    p=l*n+r
    return p*2+s

def unpack(p):
    p,s=divmod(p,2)
    l,r=divmod(p,n)
    return l,r,s

n=II()
aa=LI()

hp=[]
dist=[inf]*(n*n*2)

p=pack(0,n-1,0)
dist[p]=aa[0]
heappush(hp,(aa[0],p))
p=pack(0,n-1,1)
dist[p]=aa[-1]
heappush(hp,(aa[-1],p))

def push(d,p):
    if d>=dist[p]:return
    dist[p]=d
    heappush(hp,(d,p))

while hp:
    d,p=heappop(hp)
    if d>dist[p]:continue
    l,r,s=unpack(p)
    if l==r:
        print(d)
        exit()
    if s:
        nd=max(d+1,aa[r-1])
        np=pack(l,r-1,1)
        push(nd,np)
        nd=max(d+r-l,aa[l])
        np=pack(l,r-1,0)
        push(nd,np)
    else:
        nd=max(d+1,aa[l+1])
        np=pack(l+1,r,0)
        push(nd,np)
        nd=max(d+r-l,aa[r])
        np=pack(l+1,r,1)
        push(nd,np)
0