結果

問題 No.695 square1001 and Permutation 4
ユーザー cielciel
提出日時 2018-06-10 23:29:05
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 1,254 ms / 7,000 ms
コード長 796 bytes
コンパイル時間 504 ms
コンパイル使用メモリ 85,940 KB
実行使用メモリ 41,992 KB
最終ジャッジ日時 2023-09-30 01:37:09
合計ジャッジ時間 6,859 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 36 ms
5,060 KB
testcase_02 AC 71 ms
12,816 KB
testcase_03 AC 38 ms
12,768 KB
testcase_04 AC 178 ms
12,864 KB
testcase_05 AC 311 ms
12,800 KB
testcase_06 AC 636 ms
22,632 KB
testcase_07 AC 313 ms
22,640 KB
testcase_08 AC 422 ms
22,524 KB
testcase_09 AC 752 ms
22,524 KB
testcase_10 AC 130 ms
6,968 KB
testcase_11 AC 1,254 ms
41,676 KB
testcase_12 AC 943 ms
41,992 KB
testcase_13 AC 684 ms
41,592 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 j = 0; 2 * j < n; j++) {
			if (2 * (j + e) >= n && j + e < n) {
				r = (r + 1LL * v[j] * v[n - j - 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