結果

問題 No.695 square1001 and Permutation 4
ユーザー cielciel
提出日時 2018-06-10 21:54:06
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 630 bytes
コンパイル時間 531 ms
コンパイル使用メモリ 82,912 KB
実行使用メモリ 80,868 KB
最終ジャッジ日時 2023-09-30 01:35:51
合計ジャッジ時間 5,075 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 34 ms
6,900 KB
testcase_02 AC 66 ms
22,640 KB
testcase_03 AC 48 ms
22,576 KB
testcase_04 AC 163 ms
22,740 KB
testcase_05 AC 242 ms
22,580 KB
testcase_06 AC 559 ms
41,604 KB
testcase_07 AC 318 ms
41,556 KB
testcase_08 AC 247 ms
41,572 KB
testcase_09 AC 400 ms
41,500 KB
testcase_10 AC 113 ms
10,852 KB
testcase_11 MLE -
testcase_12 MLE -
testcase_13 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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