結果

問題 No.1868 Teleporting Cyanmond
ユーザー titiatitia
提出日時 2022-03-11 21:30:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 908 ms / 2,000 ms
コード長 846 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 10,988 KB
実行使用メモリ 19,236 KB
最終ジャッジ日時 2023-10-14 06:20:49
合計ジャッジ時間 13,498 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,940 KB
testcase_01 AC 15 ms
7,808 KB
testcase_02 AC 15 ms
7,784 KB
testcase_03 AC 908 ms
17,476 KB
testcase_04 AC 653 ms
15,524 KB
testcase_05 AC 43 ms
8,760 KB
testcase_06 AC 140 ms
10,052 KB
testcase_07 AC 423 ms
13,156 KB
testcase_08 AC 251 ms
11,036 KB
testcase_09 AC 376 ms
12,884 KB
testcase_10 AC 822 ms
16,368 KB
testcase_11 AC 26 ms
8,412 KB
testcase_12 AC 201 ms
10,832 KB
testcase_13 AC 335 ms
14,692 KB
testcase_14 AC 693 ms
18,152 KB
testcase_15 AC 449 ms
15,096 KB
testcase_16 AC 84 ms
9,580 KB
testcase_17 AC 146 ms
10,548 KB
testcase_18 AC 648 ms
19,040 KB
testcase_19 AC 648 ms
19,108 KB
testcase_20 AC 646 ms
19,232 KB
testcase_21 AC 646 ms
19,064 KB
testcase_22 AC 647 ms
19,112 KB
testcase_23 AC 608 ms
19,096 KB
testcase_24 AC 605 ms
19,224 KB
testcase_25 AC 609 ms
19,236 KB
testcase_26 AC 609 ms
19,076 KB
testcase_27 AC 608 ms
19,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N=int(input())
R=list(map(int,input().split()))

seg_el=1<<((N+1).bit_length()) # Segment treeの台の要素数
SEG=[1<<31]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化

def getvalue(n,seg_el): # 一点の値を取得
    i=n+seg_el
    ANS=1<<31
    
    ANS=min(SEG[i],ANS)
    i>>=1# 子ノードへ
    
    while i!=0:
        ANS=min(SEG[i],ANS)
        i>>=1

    return ANS

def updates(l,r,x): # 区間[l,r)のminを更新.
    L=l+seg_el
    R=r+seg_el

    while L<R:
        if L & 1:
            SEG[L]=min(x,SEG[L])
            L+=1

        if R & 1:
            R-=1
            SEG[R]=min(x,SEG[R])
        L>>=1
        R>>=1

updates(1,2,0)

for i in range(1,N):
    r=R[i-1]
    updates(i,r+1,getvalue(i,seg_el)+1)

print(getvalue(N,seg_el))
0