結果

問題 No.695 square1001 and Permutation 4
ユーザー cielciel
提出日時 2018-06-10 23:34:58
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 1,227 ms / 7,000 ms
コード長 733 bytes
コンパイル時間 515 ms
コンパイル使用メモリ 83,332 KB
実行使用メモリ 41,660 KB
最終ジャッジ日時 2023-09-30 01:36:45
合計ジャッジ時間 6,773 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 32 ms
5,060 KB
testcase_02 AC 67 ms
12,872 KB
testcase_03 AC 34 ms
12,888 KB
testcase_04 AC 160 ms
12,856 KB
testcase_05 AC 296 ms
12,872 KB
testcase_06 AC 600 ms
22,588 KB
testcase_07 AC 278 ms
22,652 KB
testcase_08 AC 397 ms
22,536 KB
testcase_09 AC 739 ms
22,572 KB
testcase_10 AC 123 ms
6,940 KB
testcase_11 AC 1,227 ms
41,552 KB
testcase_12 AC 898 ms
41,660 KB
testcase_13 AC 611 ms
41,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

int solve(int n,int M,const vector<int> &x){
	int m=n/2,r=0;
	vector<int> v(n-m);v[0]=1;
	for(int i=1;i<n-m;i++)for(auto &e:x){
		if(e<=i)v[i]=(v[i]+v[i-e])%M;
	}
	for(auto &e:x)for(int i=max(m-e,0);i<min(n-e,m);i++){
		r=(r+1LL*v[i]*v[n-i-e-1])%M;
	}
	return r;
}

long long pow(long long x,long long y,long long mod){
	long long z=1;
	for(;y;y>>=1){
		if(y&1)z=z*x%mod;
		x=x*x%mod;
	}
	return z;
}

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	vector<int>x(m);
	for(int i=0;i<m;i++)scanf("%d",&x[i]);
	int M1=168647939,M2=592951213;
	int R1=solve(n,M1,x),R2=solve(n,M2,x);
	long long Rm=(R2-R1+M2)*pow(M1,M2-2,M2)%M2;
	printf("%lld\n",1LL*Rm*M1+R1);
}
0