結果
問題 | No.1097 Remainder Operation |
ユーザー | vwxyz |
提出日時 | 2024-07-17 15:19:47 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,053 ms / 2,000 ms |
コード長 | 2,334 bytes |
コンパイル時間 | 461 ms |
コンパイル使用メモリ | 82,704 KB |
実行使用メモリ | 157,696 KB |
最終ジャッジ日時 | 2024-07-17 15:20:01 |
合計ジャッジ時間 | 13,527 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
52,736 KB |
testcase_01 | AC | 43 ms
52,352 KB |
testcase_02 | AC | 61 ms
62,592 KB |
testcase_03 | AC | 61 ms
62,848 KB |
testcase_04 | AC | 54 ms
62,080 KB |
testcase_05 | AC | 58 ms
62,592 KB |
testcase_06 | AC | 61 ms
62,848 KB |
testcase_07 | AC | 181 ms
84,188 KB |
testcase_08 | AC | 176 ms
84,192 KB |
testcase_09 | AC | 172 ms
84,116 KB |
testcase_10 | AC | 175 ms
84,168 KB |
testcase_11 | AC | 180 ms
84,068 KB |
testcase_12 | AC | 765 ms
157,696 KB |
testcase_13 | AC | 881 ms
157,568 KB |
testcase_14 | AC | 901 ms
157,696 KB |
testcase_15 | AC | 913 ms
157,568 KB |
testcase_16 | AC | 814 ms
157,596 KB |
testcase_17 | AC | 607 ms
157,696 KB |
testcase_18 | AC | 594 ms
156,256 KB |
testcase_19 | AC | 768 ms
156,160 KB |
testcase_20 | AC | 812 ms
156,160 KB |
testcase_21 | AC | 1,053 ms
156,160 KB |
testcase_22 | AC | 1,019 ms
156,416 KB |
ソースコード
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,edge=False): 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] if not edge: retu=self.f(retu,self.lst[N]) return N,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 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,True) ans=r+c*N print(ans)