結果

問題 No.2581 [Cherry Anniversary 3] 28輪の桜のブーケ
ユーザー 👑 p-adicp-adic
提出日時 2023-12-05 01:41:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 800 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 12,160 KB
実行使用メモリ 17,044 KB
最終ジャッジ日時 2023-12-08 23:30:41
合計ジャッジ時間 6,169 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 164 ms
17,044 KB
testcase_01 AC 239 ms
11,648 KB
testcase_02 AC 831 ms
13,952 KB
testcase_03 TLE -
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 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

I,F=input,range
J=lambda:map(int,I().split())
M=int(I())
G=[list(J())for i in F(2)]
C=[0]*15
L=[{}for i in F(15)]
R=[{}for i in F(15)]
for i in F(1<<14):
	l=r=m=0
	for d in F(14):
		b=(i>>d)&1
		m,l,r=m+1-b,l+G[b][d],r+G[b][14+d]
	if l%M in L[m]:L[m][l%M]+=1
	else:L[m][l%M]=1
	if r%M in R[m]:R[m][r%M]+=1
	else:R[m][r%M]=1
T=[]
S=[{}for i in F(15)]
for e in F(15):
	l=0
	for i in sorted(R[e]):S[e][i],l=l,l+R[e][i]
	S[e][M]=l
	T+=[sorted(S[e])]
Q=int(I())
for q in F(Q):
	K,X=J()
	a=0
	for c in F(max(0,K-14),min(15,K+1)):
		e=K-c
		for i in L[c]:
			b,l,r=i>X,-1,len(T[e])-1
			while l+1<r:
				m=(l+r)//2
				if T[e][m]<M-i:l=m
				else:r=m
			l,s=-1,len(T[e])-1
			while l+1<s:
				m=(l+s)//2
				if T[e][m]<M*b+X-i:l=m
				else:s=m
			a+=L[c][i]*(S[e][T[e][r]]-S[e][T[e][s]]+S[e][M]*b)
	print(a)
0