712D - Memory and Scores - CodeForces Solution


combinatorics dp math *2200

Please click on ads to support us..

C++ Code:

/* Code by pp_orange */
#include<bits/stdc++.h>
#define m_p(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define ll long long
#define ull unsigned long long
#define inf 0x7FFFFFFF
#define inff 9223372036854775807
#define rep(i,l,r) for(int i=l;i<r;++i)
#define repp(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r-1;i>=l;--i)
#define go(i,x,y) for(int i=fir[x],y=e[i];i;y=e[i=nxt[i]])
#define pii pair<int,int>
#define fi first
#define se second
#define p_q priority_queue
#define Kill(x) {cout<<x<<endl;return 0;}
#define all(x) x.begin(),x.end()
#define mod 1000000007
using namespace std;
inline int rd(){
    int x(0),f(1);char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();}
    while (isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*f;
}
inline void out(int X){
	if(X<0) {X=~(X-1); putchar('-');}
	if(X>9) out(X/10);
	putchar(X%10+'0');
}
ll pw(int x,int d){
	if(!d)return 1;
	ll t = pw(x,d>>1);
	t = t*t%mod;
	if(d&1)return t*x%mod;
	return t;
}
//#define pp_orange
#define Base 202105
ll dp[2][Base<<1];
signed main(){
	#ifdef pp_orange
    freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
	#endif
	int a = rd();
	a -= rd();
	int k = rd();
	int t = rd();
	dp[0][Base+a] = 1;
	int nw = 1,lst = 0;
	t <<= 1;
	
	
	rep(i,0,t){
		memset(dp[nw],0,sizeof(dp[nw]));
		rep(j,1,(Base<<1))dp[lst][j] += dp[lst][j-1];
		rep(j,1,(Base<<1)){
			dp[nw][j] = (dp[lst][min(j+k,(Base<<1)-1)]-dp[lst][max(0,j-k-1)])%mod;
		}
		nw ^= 1;
		lst ^= 1;
	}
	
	ll ans = 0;
	rep(i,Base+1,(Base<<1)){
		ans = (dp[lst][i]+ans)%mod;
	}
	cout<<ans<<endl;
	return 0;
}


Comments

Submit
0 Comments
More Questions

677C - Vanya and Label
1583B - Omkar and Heavenly Tree
1703C - Cypher
1511C - Yet Another Card Deck
1698A - XOR Mixup
1702E - Split Into Two Sets
1703B - ICPC Balloons
1702F - Equate Multisets
1700A - Optimal Path
665C - Simple Strings
1708A - Difference Operations
1703E - Mirror Grid
1042A - Benches
1676B - Equal Candies
1705B - Mark the Dust Sweeper
1711A - Perfect Permutation
1701B - Permutation
1692A - Marathon
1066A - Vova and Train
169B - Replacing Digits
171D - Broken checker
380C - Sereja and Brackets
1281B - Azamon Web Services
1702A - Round Down the Price
1681C - Double Sort
12A - Super Agent
1709A - Three Doors
1680C - Binary String
1684B - Z mod X = C
1003A - Polycarp's Pockets