結果

問題 No.695 square1001 and Permutation 4
ユーザー cielciel
提出日時 2020-11-13 14:09:20
言語 Crystal
(1.11.2)
結果
AC  
実行時間 1,354 ms / 7,000 ms
コード長 415 bytes
コンパイル時間 17,777 ms
コンパイル使用メモリ 255,620 KB
実行使用メモリ 43,588 KB
最終ジャッジ日時 2023-09-13 12:37:33
合計ジャッジ時間 24,191 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,428 KB
testcase_01 AC 38 ms
6,240 KB
testcase_02 AC 70 ms
14,096 KB
testcase_03 AC 50 ms
14,096 KB
testcase_04 AC 168 ms
14,196 KB
testcase_05 AC 303 ms
14,160 KB
testcase_06 AC 609 ms
24,092 KB
testcase_07 AC 327 ms
23,952 KB
testcase_08 AC 460 ms
23,864 KB
testcase_09 AC 777 ms
23,892 KB
testcase_10 AC 125 ms
8,320 KB
testcase_11 AC 1,354 ms
43,588 KB
testcase_12 AC 1,007 ms
43,444 KB
testcase_13 AC 724 ms
43,484 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

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)*442445312%m2
puts rm*m1+r1
0