結果
問題 | No.1097 Remainder Operation |
ユーザー | vwxyz |
提出日時 | 2024-07-17 15:16:24 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,291 bytes |
コンパイル時間 | 535 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 213,664 KB |
最終ジャッジ日時 | 2024-07-17 15:16:32 |
合計ジャッジ時間 | 7,851 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
17,952 KB |
testcase_01 | AC | 31 ms
11,008 KB |
testcase_02 | AC | 34 ms
11,136 KB |
testcase_03 | AC | 34 ms
11,136 KB |
testcase_04 | AC | 33 ms
11,136 KB |
testcase_05 | AC | 33 ms
11,136 KB |
testcase_06 | AC | 33 ms
11,136 KB |
testcase_07 | AC | 373 ms
32,000 KB |
testcase_08 | AC | 413 ms
32,000 KB |
testcase_09 | AC | 369 ms
32,128 KB |
testcase_10 | AC | 380 ms
31,872 KB |
testcase_11 | AC | 407 ms
31,872 KB |
testcase_12 | TLE | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
ソースコード
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: K=self.N self.k=K.bit_length() self.permutation_doubling=[[None]*self.N for k in range(self.k)] for n in range(self.N): self.permutation_doubling[0][n]=self.permutation[n] if self.lst!=None: self.doubling=[[self.e]*self.N for k in range(self.k)] for n in range(self.N): self.doubling[0][n]=self.lst[n] for k in range(1,self.k): for n in range(self.N): if self.permutation_doubling[k-1][n]!=None: self.permutation_doubling[k][n]=self.permutation_doubling[k-1][self.permutation_doubling[k-1][n]] if self.f!=None: self.doubling[k][n]=self.f(self.doubling[k-1][n],self.doubling[k-1][self.permutation_doubling[k-1][n]]) 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[k][N] 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[k][N]==None: return None retu=self.f(retu,self.doubling[k][N]) N=self.permutation_doubling[k][N] return N,self.f(retu,self.lst[N]) 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 is_ok(self.permutation_doubling[k][x]): K|=1<<k x=self.permutation_doubling[k][x] return K,x N=int(input()) A=list(map(int,input().split())) perm=[None]*N cnt=[None]*N for x in range(N): perm[x]=(x+A[x%N])%N cnt[x]=(x+A[x%N])//N Q=int(input()) PD=Path_Doubling(N,perm,cnt,lambda c0,c1:c0+c1,0) PD.Build_Next(10**12) for q in range(Q): K=int(input()) r,c=PD.Doubling(0,K-1) r=perm[r] ans=r+c*N print(ans)