結果

問題 No.695 square1001 and Permutation 4
ユーザー cielciel
提出日時 2020-08-14 01:30:41
言語 Crystal
(1.11.2)
結果
AC  
実行時間 1,355 ms / 7,000 ms
コード長 540 bytes
コンパイル時間 20,268 ms
コンパイル使用メモリ 255,692 KB
実行使用メモリ 43,468 KB
最終ジャッジ日時 2023-09-13 11:41:06
合計ジャッジ時間 24,207 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,376 KB
testcase_01 AC 38 ms
6,388 KB
testcase_02 AC 72 ms
14,168 KB
testcase_03 AC 46 ms
14,064 KB
testcase_04 AC 168 ms
14,160 KB
testcase_05 AC 304 ms
14,020 KB
testcase_06 AC 611 ms
23,924 KB
testcase_07 AC 325 ms
24,036 KB
testcase_08 AC 459 ms
23,928 KB
testcase_09 AC 778 ms
23,852 KB
testcase_10 AC 125 ms
8,228 KB
testcase_11 AC 1,355 ms
43,400 KB
testcase_12 AC 1,010 ms
43,432 KB
testcase_13 AC 721 ms
43,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env crystal

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