結果

問題 No.2581 [Cherry Anniversary 3] 28輪の桜のブーケ
ユーザー 👑 p-adicp-adic
提出日時 2023-12-05 01:40:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,006 ms / 3,000 ms
コード長 800 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 78,912 KB
最終ジャッジ日時 2023-12-08 23:30:47
合計ジャッジ時間 15,299 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
62,244 KB
testcase_01 AC 95 ms
76,968 KB
testcase_02 AC 124 ms
77,636 KB
testcase_03 AC 426 ms
78,788 KB
testcase_04 AC 279 ms
78,264 KB
testcase_05 AC 131 ms
78,272 KB
testcase_06 AC 344 ms
77,508 KB
testcase_07 AC 363 ms
78,392 KB
testcase_08 AC 127 ms
77,504 KB
testcase_09 AC 252 ms
78,264 KB
testcase_10 AC 418 ms
78,392 KB
testcase_11 AC 162 ms
78,524 KB
testcase_12 AC 468 ms
78,808 KB
testcase_13 AC 460 ms
77,892 KB
testcase_14 AC 500 ms
77,624 KB
testcase_15 AC 412 ms
78,404 KB
testcase_16 AC 428 ms
78,392 KB
testcase_17 AC 412 ms
78,396 KB
testcase_18 AC 555 ms
78,264 KB
testcase_19 AC 505 ms
78,912 KB
testcase_20 AC 529 ms
78,496 KB
testcase_21 AC 479 ms
78,264 KB
testcase_22 AC 1,003 ms
77,636 KB
testcase_23 AC 1,006 ms
77,756 KB
testcase_24 AC 986 ms
77,636 KB
testcase_25 AC 979 ms
77,764 KB
testcase_26 AC 980 ms
77,636 KB
testcase_27 AC 58 ms
70,584 KB
testcase_28 AC 82 ms
77,624 KB
testcase_29 AC 882 ms
78,404 KB
testcase_30 AC 71 ms
70,680 KB
testcase_31 AC 417 ms
77,764 KB
権限があれば一括ダウンロードができます

ソースコード

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