結果

問題 No.1868 Teleporting Cyanmond
ユーザー ygd.ygd.
提出日時 2022-03-16 22:40:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,243 ms / 2,000 ms
コード長 2,033 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 12,004 KB
実行使用メモリ 21,848 KB
最終ジャッジ日時 2023-10-25 06:16:15
合計ジャッジ時間 19,887 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,320 KB
testcase_01 AC 30 ms
10,320 KB
testcase_02 AC 29 ms
10,320 KB
testcase_03 AC 1,243 ms
19,472 KB
testcase_04 AC 893 ms
17,592 KB
testcase_05 AC 66 ms
10,804 KB
testcase_06 AC 198 ms
12,044 KB
testcase_07 AC 592 ms
14,812 KB
testcase_08 AC 349 ms
13,540 KB
testcase_09 AC 523 ms
14,492 KB
testcase_10 AC 1,134 ms
19,156 KB
testcase_11 AC 44 ms
10,508 KB
testcase_12 AC 283 ms
13,008 KB
testcase_13 AC 486 ms
15,372 KB
testcase_14 AC 996 ms
20,972 KB
testcase_15 AC 638 ms
17,088 KB
testcase_16 AC 125 ms
11,716 KB
testcase_17 AC 218 ms
12,856 KB
testcase_18 AC 955 ms
21,848 KB
testcase_19 AC 959 ms
21,848 KB
testcase_20 AC 958 ms
21,848 KB
testcase_21 AC 965 ms
21,848 KB
testcase_22 AC 962 ms
21,848 KB
testcase_23 AC 918 ms
21,848 KB
testcase_24 AC 914 ms
21,848 KB
testcase_25 AC 914 ms
21,848 KB
testcase_26 AC 914 ms
21,848 KB
testcase_27 AC 917 ms
21,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline
#input = sys.stdin.buffer.readline #文字列はダメ
#sys.setrecursionlimit(1000000)
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict 
#from collections import deque
#import copy
#import math
#from functools import lru_cache
#@lru_cache(maxsize=None)
#MOD = pow(10,9) + 7
#MOD = 998244353
#dx = [1,0,-1,0]
#dy = [0,1,0,-1]
#dx8 = [1,1,0,-1,-1,-1,0,1]
#dy8 = [0,1,1,1,0,-1,-1,-1]

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r): #これで[l,r)から取り出す。
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)

def main():
    N = int(input()); INF = pow(10,9)
    R = list(map(int,input().split()))
    #R = [r-1 for r in R]

    Tree = SegmentTree([INF]*N, min, INF)
    Tree.update(N-1,0)

    for i in reversed(range(N-1)):
        temp = Tree.sum(i+1,R[i])
        Tree.update(i, temp+1)
    
    ans = Tree[0]
    print(ans)




if __name__ == '__main__':
    main()
0