結果

問題 No.97 最大の値を求めるくえり
ユーザー ytftytft
提出日時 2022-11-12 07:32:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 4,054 ms / 5,000 ms
コード長 664 bytes
コンパイル時間 1,269 ms
コンパイル使用メモリ 86,988 KB
実行使用メモリ 91,368 KB
最終ジャッジ日時 2023-10-12 00:13:17
合計ジャッジ時間 15,786 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 182 ms
81,400 KB
testcase_01 AC 191 ms
91,328 KB
testcase_02 AC 751 ms
83,440 KB
testcase_03 AC 4,054 ms
83,244 KB
testcase_04 AC 228 ms
83,076 KB
testcase_05 AC 238 ms
83,180 KB
testcase_06 AC 243 ms
82,984 KB
testcase_07 AC 253 ms
82,868 KB
testcase_08 AC 2,191 ms
83,604 KB
testcase_09 AC 928 ms
83,412 KB
testcase_10 AC 770 ms
83,516 KB
testcase_11 AC 718 ms
83,632 KB
testcase_12 AC 436 ms
83,736 KB
testcase_13 AC 417 ms
83,488 KB
testcase_14 AC 388 ms
83,680 KB
testcase_15 AC 306 ms
83,812 KB
testcase_16 AC 295 ms
83,708 KB
testcase_17 AC 288 ms
86,916 KB
testcase_18 AC 288 ms
91,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,threading
input=lambda:sys.stdin.readline().rstrip()
x,y,z,w=123456789,362436069,521288629,88675123
mod=100003
def inv(A):
	rem=mod-2
	temp=A
	ret=1
	while rem:
		if rem%2:
			ret=(ret*temp)%mod
		temp=(temp**2)%mod
		rem>>=1
	return ret
def calc1(A,Q):
	ret=0
	for i in A:
		ret=max(ret,(Q*i)%mod)
	return ret
def calc2(B,Q):
	invQ=inv(Q)
	for i in range(mod-1,-1,-1):
		if (i*invQ)%mod in B:
			return i
N,M=map(int,input().split())
A=[0]*N
for i in range(N):
	t=x^((x<<11)%(1<<32))
	x,y,z=y,z,w
	w=w^(w>>19)^(t^(t>>8))
	A[i]=w%mod
B=set(A)
for i in range(M):
	Q=int(input())
	if Q==0:
		print(0)
		continue
	print(calc1(A,Q) if N<100 else calc2(B,Q))
0