考试的时候没有做出来。。。

想到了答案一定是一段连续的区间,一直在纠结BFS判断最后的可行1数。

原来直接模拟一遍就可以算出来最后的端点。。。

剩下的就是组合数取模了,用逆元就行了。。。

# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi 3.1415926535
# define eps 1e-
# define MOD
# define INF
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int res=, flag=;
char ch;
if((ch=getchar())=='-') flag=;
else if(ch>=''&&ch<='') res=ch-'';
while((ch=getchar())>=''&&ch<='') res=res*+(ch-'');
return flag?-res:res;
}
void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
const int N=;
//Code begin... LL f[N];
LL pow_mod(LL a, LL n, LL mod){
LL ret=, tmp=a%mod;
while (n) {
if (n&) ret=ret*tmp%MOD;
tmp=tmp*tmp%MOD;
n>>=;
}
return ret;
}
LL inv(LL a, LL mod){return pow_mod(a,mod-,mod);}
void init(){
f[]=;
FO(i,,N) f[i]=(f[i-]*i)%MOD;
}
int main ()
{
int n, m, x, l, r, tmpl, tmpr;
LL ans;
init();
while (~scanf("%d%d",&n,&m)) {
l=r=;
ans=;
FOR(i,,n) {
scanf("%d",&x);
if (l>=x) tmpl=l-x;
else if(r>=x) tmpl=((l%)==(x%))?:;
else tmpl=x-r;
if (r+x<=m) tmpr=r+x;
else if(l+x<=m) tmpr=(((l+x)%)==(m%)?m:m-);
else tmpr=*m-l-x;
l=tmpl; r=tmpr;
}
for (int i=l; i<=r; i+=) ans=(ans+(f[m]*inv(f[i]*f[m-i]%MOD,MOD))%MOD)%MOD;
printf("%lld\n",ans);
}
return ;
}
05-11 22:43