結果

問題 No.1013 〇マス進む
ユーザー vwxyzvwxyz
提出日時 2023-03-31 10:52:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,179 ms / 2,000 ms
コード長 2,378 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 81,680 KB
実行使用メモリ 255,808 KB
最終ジャッジ日時 2023-10-23 22:52:17
合計ジャッジ時間 25,934 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,404 KB
testcase_01 AC 37 ms
53,404 KB
testcase_02 AC 37 ms
53,404 KB
testcase_03 AC 56 ms
66,072 KB
testcase_04 AC 49 ms
61,948 KB
testcase_05 AC 57 ms
66,072 KB
testcase_06 AC 53 ms
63,980 KB
testcase_07 AC 60 ms
68,120 KB
testcase_08 AC 56 ms
66,044 KB
testcase_09 AC 61 ms
68,104 KB
testcase_10 AC 62 ms
68,116 KB
testcase_11 AC 58 ms
66,072 KB
testcase_12 AC 61 ms
68,120 KB
testcase_13 AC 87 ms
77,840 KB
testcase_14 AC 246 ms
103,432 KB
testcase_15 AC 385 ms
106,928 KB
testcase_16 AC 430 ms
123,864 KB
testcase_17 AC 215 ms
93,360 KB
testcase_18 AC 284 ms
106,540 KB
testcase_19 AC 162 ms
89,312 KB
testcase_20 AC 466 ms
118,040 KB
testcase_21 AC 209 ms
97,320 KB
testcase_22 AC 264 ms
97,328 KB
testcase_23 AC 118 ms
81,704 KB
testcase_24 AC 592 ms
147,168 KB
testcase_25 AC 556 ms
118,264 KB
testcase_26 AC 126 ms
85,708 KB
testcase_27 AC 178 ms
91,768 KB
testcase_28 AC 123 ms
81,772 KB
testcase_29 AC 499 ms
116,296 KB
testcase_30 AC 196 ms
94,804 KB
testcase_31 AC 344 ms
116,172 KB
testcase_32 AC 233 ms
101,696 KB
testcase_33 AC 380 ms
146,912 KB
testcase_34 AC 751 ms
198,824 KB
testcase_35 AC 751 ms
194,368 KB
testcase_36 AC 103 ms
79,884 KB
testcase_37 AC 102 ms
79,740 KB
testcase_38 AC 778 ms
217,420 KB
testcase_39 AC 245 ms
110,084 KB
testcase_40 AC 869 ms
201,980 KB
testcase_41 AC 171 ms
93,444 KB
testcase_42 AC 380 ms
143,340 KB
testcase_43 AC 231 ms
97,056 KB
testcase_44 AC 393 ms
148,404 KB
testcase_45 AC 332 ms
136,556 KB
testcase_46 AC 188 ms
96,248 KB
testcase_47 AC 335 ms
118,756 KB
testcase_48 AC 471 ms
159,804 KB
testcase_49 AC 757 ms
201,260 KB
testcase_50 AC 577 ms
179,236 KB
testcase_51 AC 494 ms
166,384 KB
testcase_52 AC 132 ms
88,256 KB
testcase_53 AC 158 ms
91,972 KB
testcase_54 AC 544 ms
193,656 KB
testcase_55 AC 206 ms
97,696 KB
testcase_56 AC 807 ms
230,124 KB
testcase_57 AC 657 ms
174,216 KB
testcase_58 AC 1,179 ms
255,660 KB
testcase_59 AC 1,039 ms
255,800 KB
testcase_60 AC 857 ms
255,808 KB
testcase_61 AC 433 ms
120,808 KB
testcase_62 AC 146 ms
98,264 KB
testcase_63 AC 37 ms
53,360 KB
testcase_64 AC 38 ms
53,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline

class Path_Doubling:
    def __init__(self,N,permutation,lst=None,f=None,e=None):
        self.N=N
        self.permutation=permutation
        self.lst=lst
        self.f=f
        self.e=e

    def Build_Next(self,K=None):
        if K==None:
            self.K=self.N
        else:
            self.K=K
        self.k=self.K.bit_length()
        self.permutation_doubling=[[self.permutation[n]] for n in range(self.N)]
        if self.lst!=None:
            self.doubling=[[self.lst[n]] for n in range(self.N)]
        for k in range(1,self.k):
            for n in range(self.N):
                if self.permutation_doubling[n][k-1]==None:
                    self.permutation_doubling[n].append(None)
                    if self.f!=None:
                        self.doubling[n].append(None)
                if self.permutation_doubling[n][k-1]!=None:
                    self.permutation_doubling[n].append(self.permutation_doubling[self.permutation_doubling[n][k-1]][k-1])
                    if self.f!=None:
                        self.doubling[n].append(self.f(self.doubling[n][k-1],self.doubling[self.permutation_doubling[n][k-1]][k-1]))

    def Permutation_Doubling(self,N,K):
        if K<0 or 1<<self.k<=K:
            return None
        for k in range(self.k):
            if K>>k&1 and N!=None:
                N=self.permutation_doubling[N][k]
        return N

    def Doubling(self,N,K):
        if K<0:
            return self.e
        retu=self.e
        for k in range(self.k):
            if K>>k&1:
                if self.permutation_doubling[N][k]==None:
                    return None
                retu=self.f(retu,self.doubling[N][k])
                N=self.permutation_doubling[N][k]
        return retu

    def Bisect(self,x,is_ok):
        if not is_ok(x):
            return -1,None
        K=0
        for k in range(self.k-1,-1,-1):
            if K|1<<k<=self.K and is_ok(self.permutation_doubling[x][k]):
                K|=1<<k
                x=self.permutation_doubling[x][k]
        return K,x

N,K=map(int,readline().split())
P=list(map(int,readline().split()))
PD=Path_Doubling(N,[(P[i]+i)%N for i in range(N)],[(i+P[i])//N for i in range(N)],lambda x,y:x+y,0)
PD.Build_Next(K)
for i in range(N):
    pd=PD.Permutation_Doubling(i,K)
    d=PD.Doubling(i,K)
    ans=pd+d*N+1
    print(ans)
0