結果

問題 No.695 square1001 and Permutation 4
ユーザー cielciel
提出日時 2020-02-08 22:24:54
言語 Crystal
(1.11.2)
結果
AC  
実行時間 1,362 ms / 7,000 ms
コード長 515 bytes
コンパイル時間 18,346 ms
コンパイル使用メモリ 256,072 KB
実行使用メモリ 43,672 KB
最終ジャッジ日時 2023-09-13 10:25:45
合計ジャッジ時間 25,320 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,496 KB
testcase_01 AC 38 ms
6,296 KB
testcase_02 AC 72 ms
14,176 KB
testcase_03 AC 47 ms
14,176 KB
testcase_04 AC 169 ms
14,320 KB
testcase_05 AC 304 ms
14,124 KB
testcase_06 AC 614 ms
24,148 KB
testcase_07 AC 328 ms
24,020 KB
testcase_08 AC 463 ms
24,000 KB
testcase_09 AC 782 ms
23,984 KB
testcase_10 AC 125 ms
8,416 KB
testcase_11 AC 1,362 ms
43,532 KB
testcase_12 AC 1,011 ms
43,672 KB
testcase_13 AC 743 ms
43,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(v,n,q,x)
	m=n//2;r=0_i64
	(1...n-m).each{|i|v[i]=0}
	(1...n-m).each{|i|x.each{|e|
		e<=i && (v[i]=(v[i]+v[i-e])%q)
	}}
	x.each{|e|([m-e,0].max...[n-e,m].min).each{|i|
		r=(r+1_i64*v[i]*v[n-i-e-1])%q
	}}
	r
end

def pow(x,y,q)
	z=1_i64
	while y>0
		y%2>0 && (z=z*x%q)
		x=x*x%q
		y//=2
	end
	z
end

n,m=gets.not_nil!.split.map &.to_i
x=gets.not_nil!.split.map &.to_i
m1=168647939;m2=592951213
v=[0]*(n-n//2);v[0]=1
r1=solve(v,n,m1,x);r2=solve(v,n,m2,x)
rm=(r2-r1+m2)*pow(m1.to_i64,m2-2,m2)%m2
puts rm*m1+r1
0