結果

問題 No.1685 One by One
ユーザー 👑 kmjpkmjp
提出日時 2021-09-23 23:10:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 709 ms / 3,000 ms
コード長 2,103 bytes
コンパイル時間 2,354 ms
コンパイル使用メモリ 201,396 KB
実行使用メモリ 350,016 KB
最終ジャッジ日時 2023-09-18 20:04:37
合計ジャッジ時間 17,713 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
126,548 KB
testcase_01 AC 47 ms
126,064 KB
testcase_02 AC 53 ms
137,392 KB
testcase_03 AC 129 ms
180,284 KB
testcase_04 AC 69 ms
146,072 KB
testcase_05 AC 364 ms
251,172 KB
testcase_06 AC 169 ms
199,608 KB
testcase_07 AC 293 ms
235,568 KB
testcase_08 AC 58 ms
136,176 KB
testcase_09 AC 77 ms
152,196 KB
testcase_10 AC 574 ms
326,792 KB
testcase_11 AC 75 ms
156,256 KB
testcase_12 AC 46 ms
136,448 KB
testcase_13 AC 407 ms
265,216 KB
testcase_14 AC 151 ms
203,864 KB
testcase_15 AC 453 ms
307,600 KB
testcase_16 AC 51 ms
142,952 KB
testcase_17 AC 49 ms
138,888 KB
testcase_18 AC 51 ms
143,112 KB
testcase_19 AC 43 ms
133,484 KB
testcase_20 AC 313 ms
249,360 KB
testcase_21 AC 333 ms
248,120 KB
testcase_22 AC 334 ms
253,972 KB
testcase_23 AC 365 ms
255,328 KB
testcase_24 AC 513 ms
337,636 KB
testcase_25 AC 656 ms
348,192 KB
testcase_26 AC 528 ms
343,524 KB
testcase_27 AC 603 ms
336,320 KB
testcase_28 AC 568 ms
350,016 KB
testcase_29 AC 709 ms
348,452 KB
testcase_30 AC 554 ms
348,420 KB
testcase_31 AC 683 ms
349,776 KB
testcase_32 AC 683 ms
349,720 KB
testcase_33 AC 672 ms
348,508 KB
testcase_34 AC 43 ms
132,864 KB
testcase_35 AC 41 ms
133,004 KB
testcase_36 AC 41 ms
132,840 KB
testcase_37 AC 42 ms
132,836 KB
testcase_38 AC 330 ms
237,940 KB
testcase_39 AC 335 ms
237,952 KB
testcase_40 AC 344 ms
238,176 KB
testcase_41 AC 348 ms
237,932 KB
testcase_42 AC 41 ms
132,756 KB
testcase_43 AC 42 ms
133,000 KB
testcase_44 AC 42 ms
132,760 KB
testcase_45 AC 41 ms
132,764 KB
testcase_46 AC 119 ms
213,696 KB
testcase_47 AC 135 ms
213,852 KB
testcase_48 AC 124 ms
213,528 KB
testcase_49 AC 133 ms
213,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M;
ll dp[4040][4040];
ll dp2[4040][4040];
const ll mo=1000000007;

ll comb(int P_,int Q_) {
	static const int N_=4020;
	static ll C_[N_][N_];
	
	if(C_[0][0]==0) {
		int i,j;
		FOR(i,N_) C_[i][0]=C_[i][i]=1;
		for(i=1;i<N_;i++) for(j=1;j<i;j++) C_[i][j]=(C_[i-1][j-1]+C_[i-1][j])%mo;
	}
	if(P_<0 || P_>N_ || Q_<0 || Q_>P_) return 0;
	return C_[P_][Q_];
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	dp[0][0]=1;
	cin>>N>>M;
	FOR(i,N) {
		FOR(j,4020) dp[i+1][j+1]=(dp[i][j]+dp[i+1][j])%mo;
	}
	
	ll ret=0;
	for(int mi=0;mi<=N;mi++) {
		for(int ze=0;mi+ze<=N;ze++) {
			int pl=N-mi-ze;
			if(mi>=(N+1)/2) continue;
			if(mi+ze<(N+1)/2) continue;
			
			ll pat=comb(mi+ze,mi)*comb(N,pl)%mo;
			if((mi+pl)%2==M%2) {
				dp2[mi+pl][mi+pl]+=pat;
				if(N%2) {
					int d=mi+pl+1;
					int ma=M-(ze-abs(pl-mi));
					if(d%2!=ma%2) ma--;
					if(d<=ma) {
						dp2[mi+pl][d]+=pat;
						dp2[mi+pl][ma+2]+=mo-pat;
					}
				}
			}
			else {
				dp2[mi+pl][mi+pl+1]+=pat;
				if(N%2) {
					int d=mi+pl;
					int ma=M-(ze-abs(pl-mi));
					if(d%2!=ma%2) ma--;
					if(d<=ma) {
						dp2[mi+pl][d]+=pat;
						dp2[mi+pl][ma+2]+=mo-pat;
					}
				}
				
			}
		}
	}
	FOR(i,N+1) {
		FOR(j,M+1) {
			if(j>=2) (dp2[i][j]+=dp2[i][j-2])%=mo;
			(ret+=dp2[i][j]*dp[i][j])%=mo;
		}
	}
	cout<<ret%mo<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0