結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 235 ms
82,560 KB
testcase_01 AC 293 ms
91,912 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

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,ans):
	ret=0
	for i in A:
		ret=max(ret,(Q*i)%mod)
		if ans[0]!=-1:
			return
	ans[0]=ret
def calc2(B,Q,ans):
	invQ=inv(Q)
	for i in range(mod-1,-1,-1):
		if (i*invQ)%mod in B:
			ans[0]=i
			return
		if ans[0]!=-1:
			return
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
	ans=[-1]
	th1=threading.Thread(target=calc1,args=(A,Q,ans))
	th2=threading.Thread(target=calc2,args=(B,Q,ans))
	th1.start()
	th2.start()
	for i in threading.enumerate():
		if threading.main_thread()!=i:
			i.join()
	print(ans[0])
0