text
stringlengths 49
983k
|
|---|
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define pii pair <int , int>
#define mp make_pair
#define fs first
#define sc second
using namespace std;
typedef long long LL;
template <typename T>
void read(T &x) {
T f=1;x=0;char s=getchar();
while(s<'0'||s>'9') {if(s=='-') f=-1;s=getchar();}
while(s>='0'&&s<='9') {x=(x<<3)+(x<<1)+(s^'0');s=getchar();}
x *= f;
}
template <typename T>
void write(T x , char s='\n') {
if(!x) {putchar('0');putchar(s);return;}
if(x<0) {putchar('-');x=-x;}
T t = 0 , tmp[25] = {};
while(x) tmp[t ++] = x % 10 , x /= 10;
while(t -- > 0) putchar(tmp[t] + '0');
putchar(s);
}
const LL mod = 1e9 + 7;
LL dp[105][10005] , c[105] , b[105] , n , x , Sum[105] , Sc[105];
int main() {
read(n);
for (int i = 1; i <= n; ++i) read(c[i]) , Sc[i] = Sc[i - 1] + c[i];
for (int i = 1; i < n; ++i) read(b[i]) , b[i] += b[i - 1];
int q;
read(q);
read(x);
Sum[1] = x;
for (int i = 2; i <= n; ++i) Sum[i] = Sum[i - 1] + b[i - 1] + x;
for (int i = 0; i <= Sc[n]; ++i) dp[0][i] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = max(0ll , Sum[i]); j <= Sc[i]; ++j) {
if(j <= c[i]) dp[i][j] = dp[i - 1][j];
else dp[i][j] = (dp[i - 1][j] - dp[i - 1][j - c[i] - 1] + mod) % mod;
}
for (int j = 1; j <= Sc[n]; ++j) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
}
write(dp[n][Sc[n]]);
return 0;
}
|
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
int x=0;
bool flag=1;
char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-')
flag=0;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=(x<<1)+(x<<3)+c-'0';
c=getchar();
}
return (flag?x:~(x-1));
}
const int mod=1e9+7;
int n,q,ans,c[101],b[101],L[101],f[101][10001];
signed main()
{
n=read();
for(int i=1;i<=n;i++)
c[i]=read();
for(int i=1;i<n;i++)
b[i]=b[i-1]+read();
q=read();
while(q--)
{
int x=read(),cnt=0,sum=0;
ans=0;
for(int i=1;i<=n;i++)
{
L[i]=max(0ll,x*i+cnt);
cnt+=b[i];
}
f[0][0]=1;
for(int i=1;i<=n;i++)
{
sum+=c[i];
for(int l=L[i];l<=sum;l++)
{
for(int j=0;j<=l&&j<=c[i];j++)
(f[i][l]+=f[i-1][l-j])%=mod;
if(i==n)
(ans+=f[i][l])%=mod;
}
}
cout<<ans<<endl;
}
return 0;
}
|
#include <cstdio>
#include <algorithm>
const int N=205, MOD=1000000007;
inline int mval(int x) { return x>=MOD?x-MOD:x; }
inline int fix(int x) { return x+(x>>31&MOD); }
inline void inc(int &x, int a) { x=mval(x+a); }
inline void dec(int &x, int a) { x=fix(x-a); }
int n, q, c[N], b[N], f[N][N*N], lim[N], ans[N], prod=1, lw, up;
int main()
{
scanf("%d", &n);
for(int i=1; i<=n; ++i) scanf("%d", c+i), up=std::max(up, c[i]), prod=1ll*prod*(c[i]+1)%MOD;
for(int i=2; i<=n; ++i) scanf("%d", b+i), b[i]+=b[i-1], lw+=b[i]-c[i];
lw-=c[1];
lw=-((lw+n-1)/n);
++lw;
++up;
for(int x=lw; x>lw-up; --x)
{
f[0][0]=1;
int sum=0;
for(int i=1; i<=n; ++i)
{
int l=-b[i]-x, r=l+c[i];
lim[i]=std::max(0, lim[i-1]+l);
if(sum+r<0) { goto out; }
std::fill(f[i], f[i]+sum+r-lim[i]+1, 0);
for(int j=std::max(lim[i-1], -r); j<=sum; ++j)
{
inc(f[i][std::max(0, j+l-lim[i])], f[i-1][j-lim[i-1]]);
dec(f[i][j+r+1-lim[i]], f[i-1][j-lim[i-1]]);
}
sum+=r;
for(int j=1; j<=sum-lim[i]+1; ++j) inc(f[i][j], f[i][j-1]);
}
for(int j=0; j<=sum-lim[n]; ++j) inc(ans[lw-x], f[n][j]);
out:;
}
scanf("%d", &q);
for(int i=1, x; i<=q; ++i)
{
scanf("%d", &x);
printf("%d\n", (x>lw?0:x<=lw-up?prod:ans[lw-x]));
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
const int N=105,M=1000000007,iv=(M+1)/2;
int n,t,c[N],b[N],q,x,s[N],f[N][N*N],i;
int dfs(int i,int p)
{
if(i>n)
return 1;
if(f[i][p]!=-1)
return f[i][p];
int j;
long long ss=0;
for(j=0;j<=c[i];++j)
if(p+j-s[i]>=i*x)
ss+=dfs(i+1,p+j);
return f[i][p]=ss%M;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
scanf("%d",&n);
for(i=1;i<=n;++i)
scanf("%d",&c[i]);
for(i=1;i<n;++i)
scanf("%d",&b[i]);
scanf("%d",&q);
scanf("%d",&x);
for(i=1;i<n;++i)
s[i+1]=s[i]+b[i];
for(i=2;i<=n;++i)
s[i]+=s[i-1];
memset(f,-1,sizeof(f));
cout<<dfs(1,0);
}
|
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repn(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vii vector<pii>
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int,int>>>
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define sz(x) (int)x.size()
#define all(v) (v).begin(), (v).end()
#define ret(x) return cout<<x,0;
#define rety return cout<<"YES",0;
#define retn return cout<<"NO",0;
#define fl fflush(stdout)
#define hell 1000000007
#define hell2 998244353
#define pi 3.14159265358979323846
int solve(){
int n;
cin>>n;
int c[n];
rep(i,0,n)cin>>c[i];
int b[n-1];
rep(i,0,n-1)cin>>b[i];
int q,x;
cin>>q>>x;
// int dp[10005]={0};
vi dp(100005,0);
rep(i,0,c[0]+1)dp[i]=1;
if(x>10005){
cout<<0;
return 0;
}
rep(i,0,x)dp[i]=0;
int cur=x,temp=x;
rep(i,1,n){
vi sum=dp;
rep(i,1,10005)sum[i]=(sum[i]+sum[i-1])%hell;
rep(j,0,10005){
int k=j-c[i]-1;
dp[j]=sum[j];
if(k>=0)dp[j]=(dp[j]-sum[k])%hell;
dp[j]%=hell;
}
temp=(temp+b[i-1])%hell;
cur=(cur+temp)%hell;
if(cur>10002){
cout<<0;
return 0;
}
cur=min(cur,10002LL);
rep(j,0,cur)dp[j]=0;
}
int ans=0;
rep(i,0,10005)ans=(ans+dp[i])%hell;
if(ans<0)ans+=hell;
cout<<ans;
// rep(i,0,100)cout<<dp[i]<<" ";
return 0;
}
signed main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r" , stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
// cin>>t;
while(t--){
solve(),
cout<<"\n";
}
return 0;
}
|
#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
#define int long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define mod 1000000007
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
modint &operator +=(int o){return x=x+o>=mod?x+o-mod:x+o,*this;}
modint &operator -=(int o){return x=x-o<0?x-o+mod:x-o,*this;}
modint &operator *=(int o){return x=1ll*x*o%mod,*this;}
modint &operator /=(int o){return *this *= ((modint(o))^=mod-2);}
template<class I>friend modint operator +(modint a,I b){return a+=b;}
template<class I>friend modint operator -(modint a,I b){return a-=b;}
template<class I>friend modint operator *(modint a,I b){return a*=b;}
template<class I>friend modint operator /(modint a,I b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,int b){return a.x==b;}
friend bool operator !=(modint a,int b){return a.x!=b;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
};
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
#define maxn 200005
#define inf 0x3f3f3f3f
int n,c[maxn],b[maxn],sb[maxn];
int bsum=0;
modint f[maxn],g[maxn];
inline modint sumg(int l,int r){
if(!l)return g[r];
return g[r]-g[l-1];
}
signed main()
{
n=read();
For(i,1,n)c[i]=read();
For(i,1,n-1)b[i]=read(),sb[i]=sb[i-1]+b[i];
int Q=read(),x=read(),all=0,now=0;
f[0]=1;
For(i,1,n){
For(j,0,all)g[j]=f[j],f[j]=0;
all+=c[i];
For(j,1,all)g[j]+=g[j-1];
now+=x,now+=sb[i-1];
if(now>all){
puts("0");
return 0;
}
For(j,0,all)
f[j]=sumg(max(j-c[i],0ll),j);
// cout<<now<<" "<<all<<endl;
if(now>0){
For(j,0,now-1)
f[j]=0;
}
// For(j,0,all)cout<<f[j].x<<" ";puts("");
}
modint res=0;
For(i,max(0ll,now),all)res+=f[i];
cout<<res.x;
return 0;
}
/*
*/
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 105, MOD = 1e9 + 7;
int n, f[N * N], g[N * N], b[N], sb[N], c[N];
map<int, int> ans;
int Solve(int x)
{
fill(g, g + N * N, 1);
for(int i = 1, sumc = c[1], lim; i <= n; i++, sumc += c[i])
{
lim = i * x + sb[i]; memset(f, 0, sizeof(f));
for(int j = max(0, lim); j < N * N; j++) f[j] = (g[j] - (j - c[i] - 1 >= 0 ? g[j - c[i] - 1] : 0) + MOD) % MOD;
memset(g, 0, sizeof(g)); g[0] = f[0];
for(int j = 1; j < N * N; j++) g[j] = (g[j - 1] + f[j]) % MOD;
}
return g[N * N - 1];
}
int main()
{
ios::sync_with_stdio(false);
cin >> n;
int prod = 1;
for(int i = 1; i <= n; i++) { cin >> c[i]; prod = (ll)prod * (c[i] + 1) % MOD; }
for(int i = 1; i < n; i++) cin >> b[i];
for(int i = 1; i <= n; i++) for(int j = 1; j < i; j++) sb[i] += (i - j) * b[j];
int lb = 0, rb = INT_MAX, m = *max_element(c + 1, c + n + 1);
for(int i = 1; i <= n; i++) lb = min(lb, -((sb[i] - 1) / i + 1)), rb = min(rb, (n * m - sb[i] - 1) / i + 1);
for(int i = lb; i <= rb; i++) ans[i] = Solve(i);
int q; cin >> q;
while(q--)
{
int x; cin >> x;
if(x >= lb && x <= rb) cout << ans[x] << endl;
else if(x > rb) cout << 0 << endl;
else if(x < lb) cout << prod << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define y1 y114514
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define all(a) a.begin(), a.end()
const int M = 1000000007;
const int maxn = 105;
int n;
int c[maxn];
int b[maxn];
int sum[maxn];
int ss[maxn];
int tot[maxn];
int dp[maxn][maxn * 100];
int q, x;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", c + i), tot[i] = tot[i - 1] + c[i];
for (int i = 1; i < n; ++i) {
scanf("%d", b + i);
sum[i + 1] = sum[i] + b[i];
ss[i + 1] = ss[i] + sum[i + 1];
}
scanf("%d%d", &q, &x);
dp[0][0] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= tot[i]; ++j)
if (dp[i - 1][j]) {
int limit = x * i + ss[i] - j;
// printf("i:%d j:%d limit:%d\n", i, j, limit);
for (int k = max(0, limit); k <= c[i]; ++k) {
dp[i][j + k] = dp[i][j + k] + dp[i - 1][j];
if (dp[i][j + k] >= M) dp[i][j + k] -= M;
// printf("dp[%d][%d]->%d->dp[%d][%d], cur: %d\n", i - 1, j, k, i, j + k, dp[i][j + k]);
}
}
}
// for (int i = 1; i <= n; ++i)
// for (int j = 0; j <= tot[i]; ++j) printf("dp[%d][%d]: %d\n", i, j, dp[i][j]);
int ans = 0;
for (int i = 0; i <= tot[n]; ++i) (ans += dp[n][i]) %= M;
printf("%d\n", ans);
return 0;
}
|
#include<bits/stdc++.h>
#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define per(i,a,b) for(ll i=(a);i>=(b);i--)
#define op(x) ((x&1)?x+1:x-1)
#define odd(x) (x&1)
#define even(x) (!odd(x))
#define lc(x) (x<<1)
#define rc(x) (lc(x)|1)
#define lowbit(x) (x&-x)
#define Max(a,b) (a>b?a:b)
#define Min(a,b) (a<b?a:b)
#define next Cry_For_theMoon
#define il inline
#define pb(x) push_back(x)
#define is(x) insert(x)
#define sit set<int>::iterator
#define mapit map<int,int>::iterator
#define pi pair<int,int>
#define ppi pair<int,pi>
#define pp pair<pi,pi>
#define fr first
#define se second
#define vit vector<int>::iterator
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double db;
using namespace std;
const int MAXN=110,MAXM=1e4+10,moder=1e9+7;
int n,c[MAXN],b[MAXN],q,x;
ll f[MAXN][MAXM],sum[MAXN],sum2[MAXN],ans;
int main(){
cin>>n;
rep(i,1,n)cin>>c[i];
rep(i,1,n-1)cin>>b[i];
cin>>q>>x;
rep(i,1,n){
sum2[i]=sum2[i-1]+c[i];
sum[i]=i*x;
rep(j,1,i-1){
sum[i]+=(i-j)*b[j];
}
}
f[0][0]=1;
rep(i,0,n-1){
rep(j,0,sum2[i]){
ll L=Max(0,sum[i+1]-j),R=c[i+1];
rep(k,L,R){
f[i+1][j+k]=(f[i+1][j+k]+f[i][j])%moder;
}
}
}
ll L=Max(0,sum[n]),R=sum2[n];
rep(i,L,R){
ans=(ans+f[n][i])%moder;
}
cout<<ans<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
constexpr int MAXN = 100;
constexpr int MOD = 1000000007;
constexpr int MAXTOLERANCE = 10000001; //10001; // really? TODO
int c[MAXN], b[MAXN], magic[MAXN];
int dp1[MAXTOLERANCE], dp2[MAXTOLERANCE];
int coalesce[MAXTOLERANCE+1];
int* const coal=coalesce+MAXTOLERANCE/2;
int32_t main(){
ios_base::sync_with_stdio(false);
int n,q;
cin>>n;
for (int i=0;i<n;++i){
cin>>c[i];
}
for(int i=1;i<n;++i){
cin>>b[i];
}
cin>>q;
for(int j=0;j<q;++j){
int x;
cin>>x;
/*if (x>MAXN){
cout<<0<<'\n';
continue;
}*/
magic[0]=x;
for(int i=1;i<n;++i){
magic[i]=magic[i-1]+b[i];
}
int* prev=dp1+MAXTOLERANCE/2;
//fill_n(prev-MAXTOLERANCE/2, MAXTOLERANCE, 0);
prev[x]=1;
int prev_low=x;
int prev_high=x;
int* curr=dp2+MAXTOLERANCE/2;
//fill_n(curr-MAXTOLERANCE/2, MAXTOLERANCE, 0);
for(int i=0;i<n-1;++i){
//fill_n(curr-MAXTOLERANCE/2, MAXTOLERANCE, 0);
//fill_n(coal-MAXTOLERANCE/2, MAXTOLERANCE+1, 0);
// TODO: optimize
int coal_low=LLONG_MAX;
int coal_high=LLONG_MIN;
for(int k=prev_low;k<=prev_high;++k){
int start = max(k, 0ll);
if (start <= c[i] && prev[k]>0){
int c_start = min(max(magic[i+1]-(c[i]-k), -MAXTOLERANCE/2), MAXTOLERANCE/2+1);
int c_end = min(max(magic[i+1]-(start-k)+1, -MAXTOLERANCE/2), MAXTOLERANCE/2+1);
coal[c_start]+=prev[k];
coal[c_start]%=MOD;
coal[c_end]+=(MOD-prev[k]);
coal[c_end]%=MOD;
coal_low=min(coal_low,c_start);
coal_high=max(coal_high,c_end-1);
}
/*for(int kk=start;kk<=c[i];++kk){
int ind = magic[i+1]-(kk-k);
if (ind >= -MAXTOLERANCE/2 && ind <= MAXTOLERANCE/2){
curr[ind]+=prev[k];
curr[ind]%=MOD;
}
}*/
}
int cum=0;
for(int k=coal_low;k<=coal_high;++k){
cum+=coal[k];
cum%=MOD;
curr[k]=cum;
}
fill(coal+coal_low,coal+coal_high+2,0);
fill(prev+prev_low, prev+prev_high+1,0);
prev_low=coal_low;
prev_high=coal_high;
swap(prev, curr);
/*for(int k=-10;k<=10;++k){
cout<<' '<<prev[k];
}
cout<<endl;
cout<< prev_low<<' '<<prev_high<<endl;*/
}
int ans=0;
{
//fill_n(curr-MAXTOLERANCE/2, MAXTOLERANCE, 0);
// TODO: optimize
for(int k=prev_low;k<=prev_high;++k){
int start = max(k, 0ll);
for(int kk=start;kk<=c[n-1];++kk){
ans+=prev[k];
ans%=MOD;
}
}
fill(prev+prev_low,prev+prev_high+1,0);
}
cout<<ans<<'\n';
}
}
|
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define ROF(i,a,b) for(int i=(a); i>=(b); --i)
#define pb push_back
#define eb emplace_back
#define SZ(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define make_unique(a) sort(all((a))), (a).erase(unique(all((a))),(a).end())
#define x first
#define y second
#define MP make_pair
#define MT make_tuple
#define debug(x) cout << #x << " = " << x << endl
#define debug2(x,y) FOR(i,1,y) cout << "##"; cout << #x << " = " << x << endl
#define mset(x,y) memset((x), (y), sizeof(x))
using namespace std;
typedef long long i64;
typedef long double ld;
typedef tuple<int,int,int> iii;
typedef pair<int,int> pii;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<i64>> vvl;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<i64,i64>> vpll;
int readInt(){ int a; scanf("%d",&a); return a; }
i64 readLong(){ i64 a; scanf("%lld",&a); return a;}
void readString(char *s){ scanf(" %s",s); }
string print(int a){ return to_string(a); }
string print(i64 a){ return to_string(a); }
string print(string a){ return a; }
template<typename T1, typename T2> string print(pair<T1,T2> x){ return "("+print(x.x)+","+print(x.y)+")"; }
template<typename T> string print(vector<T> v){ string ans = "[ "; for(T e : v) ans += print(e)+" "; ans += "]"; return ans; }
template<typename T> string print(T *a, T *b){ string ans = "[ "; while(a!=b) ans += print(*(a++))+" "; ans += "]"; return ans; }
const int mod = 1000000007;
int add(int a, int b){ return ((a+=b)>=mod)?a-mod:a; }
int mul(int a, int b){ return a*1ll*b%mod; }
void adding(int &a, int b){ a = add(a, b); }
int pw(int a, int b){
if(a==0) return 0;
int ans = 1, res = a;
for(int i = 1; i <= b; i<<=1, res=mul(res,res)){
if(i&b) ans = mul(ans,res);
}
return ans;
}
const int N = 102;
int dp[N][N*N];
int arbi[N];
int B[N], C[N];
int main(){
dp[0][0] = 1;
int n = readInt();
int sum = 0;
int Bsum = 0;
FOR(i, 1, n) C[i] = readInt();
FOR(i, 1, n-1){
B[i] = readInt();
Bsum += B[i];
B[i] = B[i-1]+Bsum;
}
int q = readInt();
int x = readInt();
FOR(i, 1, n){
FOR(j, 0, C[i]){
FOR(k, 0, sum){
if(k+j-B[i-1] >= x*i) adding(dp[i][k+j],dp[i-1][k]);
}
}
sum += C[i];
//cout << print(dp[i], dp[i]+sum) << endl;
}
int ans = 0;
ROF(i, sum, 0){
adding(ans, dp[n][i]);
}
printf("%d",ans);
return 0;
}
|
/**
* author: tourist
* created: 25.06.2021 18:57:29
**/
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T inverse(T a, T m) {
T u = 0, v = 1;
while (a != 0) {
T t = m / a;
m -= t * a; swap(a, m);
u -= t * v; swap(u, v);
}
assert(m == 1);
return u;
}
template <typename T>
class Modular {
public:
using Type = typename decay<decltype(T::value)>::type;
constexpr Modular() : value() {}
template <typename U>
Modular(const U& x) {
value = normalize(x);
}
template <typename U>
static Type normalize(const U& x) {
Type v;
if (-mod() <= x && x < mod()) v = static_cast<Type>(x);
else v = static_cast<Type>(x % mod());
if (v < 0) v += mod();
return v;
}
const Type& operator()() const { return value; }
template <typename U>
explicit operator U() const { return static_cast<U>(value); }
constexpr static Type mod() { return T::value; }
Modular& operator+=(const Modular& other) { if ((value += other.value) >= mod()) value -= mod(); return *this; }
Modular& operator-=(const Modular& other) { if ((value -= other.value) < 0) value += mod(); return *this; }
template <typename U> Modular& operator+=(const U& other) { return *this += Modular(other); }
template <typename U> Modular& operator-=(const U& other) { return *this -= Modular(other); }
Modular& operator++() { return *this += 1; }
Modular& operator--() { return *this -= 1; }
Modular operator++(int) { Modular result(*this); *this += 1; return result; }
Modular operator--(int) { Modular result(*this); *this -= 1; return result; }
Modular operator-() const { return Modular(-value); }
template <typename U = T>
typename enable_if<is_same<typename Modular<U>::Type, int>::value, Modular>::type& operator*=(const Modular& rhs) {
#ifdef _WIN32
uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value);
uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x), d, m;
asm(
"divl %4; \n\t"
: "=a" (d), "=d" (m)
: "d" (xh), "a" (xl), "r" (mod())
);
value = m;
#else
value = normalize(static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value));
#endif
return *this;
}
template <typename U = T>
typename enable_if<is_same<typename Modular<U>::Type, long long>::value, Modular>::type& operator*=(const Modular& rhs) {
long long q = static_cast<long long>(static_cast<long double>(value) * rhs.value / mod());
value = normalize(value * rhs.value - q * mod());
return *this;
}
template <typename U = T>
typename enable_if<!is_integral<typename Modular<U>::Type>::value, Modular>::type& operator*=(const Modular& rhs) {
value = normalize(value * rhs.value);
return *this;
}
Modular& operator/=(const Modular& other) { return *this *= Modular(inverse(other.value, mod())); }
friend const Type& abs(const Modular& x) { return x.value; }
template <typename U>
friend bool operator==(const Modular<U>& lhs, const Modular<U>& rhs);
template <typename U>
friend bool operator<(const Modular<U>& lhs, const Modular<U>& rhs);
template <typename V, typename U>
friend V& operator>>(V& stream, Modular<U>& number);
private:
Type value;
};
template <typename T> bool operator==(const Modular<T>& lhs, const Modular<T>& rhs) { return lhs.value == rhs.value; }
template <typename T, typename U> bool operator==(const Modular<T>& lhs, U rhs) { return lhs == Modular<T>(rhs); }
template <typename T, typename U> bool operator==(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) == rhs; }
template <typename T> bool operator!=(const Modular<T>& lhs, const Modular<T>& rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(const Modular<T>& lhs, U rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(U lhs, const Modular<T>& rhs) { return !(lhs == rhs); }
template <typename T> bool operator<(const Modular<T>& lhs, const Modular<T>& rhs) { return lhs.value < rhs.value; }
template <typename T> Modular<T> operator+(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) += rhs; }
template <typename T, typename U> Modular<T> operator+(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) += rhs; }
template <typename T, typename U> Modular<T> operator+(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) += rhs; }
template <typename T> Modular<T> operator-(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T, typename U> Modular<T> operator-(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T, typename U> Modular<T> operator-(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T> Modular<T> operator*(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T, typename U> Modular<T> operator*(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T, typename U> Modular<T> operator*(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T> Modular<T> operator/(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) /= rhs; }
template <typename T, typename U> Modular<T> operator/(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) /= rhs; }
template <typename T, typename U> Modular<T> operator/(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) /= rhs; }
template<typename T, typename U>
Modular<T> power(const Modular<T>& a, const U& b) {
assert(b >= 0);
Modular<T> x = a, res = 1;
U p = b;
while (p > 0) {
if (p & 1) res *= x;
x *= x;
p >>= 1;
}
return res;
}
template <typename T>
bool IsZero(const Modular<T>& number) {
return number() == 0;
}
template <typename T>
string to_string(const Modular<T>& number) {
return to_string(number());
}
// U == std::ostream? but done this way because of fastoutput
template <typename U, typename T>
U& operator<<(U& stream, const Modular<T>& number) {
return stream << number();
}
// U == std::istream? but done this way because of fastinput
template <typename U, typename T>
U& operator>>(U& stream, Modular<T>& number) {
typename common_type<typename Modular<T>::Type, long long>::type x;
stream >> x;
number.value = Modular<T>::normalize(x);
return stream;
}
/*
using ModType = int;
struct VarMod { static ModType value; };
ModType VarMod::value;
ModType& md = VarMod::value;
using Mint = Modular<VarMod>;
*/
constexpr int md = (int) 1e9 + 7;
using Mint = Modular<std::integral_constant<decay<decltype(md)>::type, md>>;
/*vector<Mint> fact(1, 1);
vector<Mint> inv_fact(1, 1);
Mint C(int n, int k) {
if (k < 0 || k > n) {
return 0;
}
while ((int) fact.size() < n + 1) {
fact.push_back(fact.back() * (int) fact.size());
inv_fact.push_back(1 / fact.back());
}
return fact[n] * inv_fact[k] * inv_fact[n - k];
}*/
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> c(n);
for (int i = 0; i < n; i++) {
cin >> c[i];
}
vector<int> b(n - 1);
for (int i = 0; i < n - 1; i++) {
cin >> b[i];
}
int tt;
cin >> tt;
vector<int> x(tt);
for (int i = 0; i < tt; i++) {
cin >> x[i];
}
for (int qq = 0; qq < tt; qq++) {
int val = x[qq];
// s = a[0] + a[1] + ... + a[i]
// s = f + (f + b[0]) + (f + b[0] + b[1]) + ... + (f + b[0] + b[1] + ... + b[i - 1])
// f = (s - b[0] * i - b[1] * (i - 1) - ... - b[i - 1]) / (i + 1)
vector<Mint> dp(1, 1);
for (int i = 0; i < n; i++) {
vector<Mint> new_dp(dp.size() + c[i], 0);
for (int j = 0; j < (int) dp.size(); j++) {
for (int v = 0; v <= c[i]; v++) {
new_dp[j + v] += dp[j];
}
}
swap(dp, new_dp);
for (int j = 0; j < (int) dp.size(); j++) {
int z = j;
for (int k = 0; k < i; k++) {
z -= b[k] * (i - k);
}
if (z < val * (i + 1)) {
dp[j] = 0;
}
}
}
cout << accumulate(dp.begin(), dp.end(), Mint(0)) << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
#define fr first
#define sc second
#define m_p make_pair
#define all(x) (x).begin(), (x).end()
#define unique(a) a.resize(unique(a.begin(), a.end()) - a.begin())
#define low_bo(a, x) ((int)(lower_bound(a.begin(), a.end(), x) - a.begin()))
#define up_bo(a, x) ((int)(upper_bound(a.begin(), a.end(), x) - a.begin()))
using namespace std;
mt19937 rnd(223);
#define TIME (clock() * 1.0 / CLOCKS_PER_SEC)
using ll = long long;
using ld = double;
namespace Ment {
template<typename T>
T inverse(T a, T m) {
T u = 0, v = 1;
while (a != 0) {
T t = m / a;
m -= t * a;
swap(a, m);
u -= t * v;
swap(u, v);
}
assert(m == 1);
return u;
}
template<typename T>
class Modular {
public:
using Type = typename decay<decltype(T::value)>::type;
constexpr Modular() : value() {}
template<typename U>
Modular(const U &x) {
value = normalize(x);
}
template<typename U>
static Type normalize(const U &x) {
Type v;
if (-mod() <= x && x < mod()) v = static_cast<Type>(x);
else v = static_cast<Type>(x % mod());
if (v < 0) v += mod();
return v;
}
const Type &operator()() const { return value; }
template<typename U>
explicit operator U() const { return static_cast<U>(value); }
constexpr static Type mod() { return T::value; }
Modular &operator+=(const Modular &other) {
if ((value += other.value) >= mod()) value -= mod();
return *this;
}
Modular &operator-=(const Modular &other) {
if ((value -= other.value) < 0) value += mod();
return *this;
}
template<typename U>
Modular &operator+=(const U &other) { return *this += Modular(other); }
template<typename U>
Modular &operator-=(const U &other) { return *this -= Modular(other); }
Modular &operator++() { return *this += 1; }
Modular &operator--() { return *this -= 1; }
Modular operator++(int) {
Modular result(*this);
*this += 1;
return result;
}
Modular operator--(int) {
Modular result(*this);
*this -= 1;
return result;
}
Modular operator-() const { return Modular(-value); }
template<typename U = T>
typename enable_if<is_same<typename Modular<U>::Type, int>::value, Modular>::type &
operator*=(const Modular &rhs) {
#ifdef _WIN32
uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value);
uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x), d, m;
asm(
"divl %4; \n\t"
: "=a" (d), "=d" (m)
: "d" (xh), "a" (xl), "r" (mod())
);
value = m;
#else
value = normalize(static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value));
#endif
return *this;
}
template<typename U = T>
typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value, Modular>::type &
operator*=(const Modular &rhs) {
int64_t q = static_cast<int64_t>(static_cast<long double>(value) * rhs.value / mod());
value = normalize(value * rhs.value - q * mod());
return *this;
}
template<typename U = T>
typename enable_if<!is_integral<typename Modular<U>::Type>::value, Modular>::type &
operator*=(const Modular &rhs) {
value = normalize(value * rhs.value);
return *this;
}
Modular &operator/=(const Modular &other) { return *this *= Modular(inverse(other.value, mod())); }
template<typename U>
friend bool operator==(const Modular<U> &lhs, const Modular<U> &rhs);
template<typename U>
friend bool operator<(const Modular<U> &lhs, const Modular<U> &rhs);
template<typename U>
friend std::istream &operator>>(std::istream &stream, Modular<U> &number);
private:
Type value;
};
template<typename T>
bool operator==(const Modular<T> &lhs, const Modular<T> &rhs) { return lhs.value == rhs.value; }
template<typename T, typename U>
bool operator==(const Modular<T> &lhs, U rhs) { return lhs == Modular<T>(rhs); }
template<typename T, typename U>
bool operator==(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) == rhs; }
template<typename T>
bool operator!=(const Modular<T> &lhs, const Modular<T> &rhs) { return !(lhs == rhs); }
template<typename T, typename U>
bool operator!=(const Modular<T> &lhs, U rhs) { return !(lhs == rhs); }
template<typename T, typename U>
bool operator!=(U lhs, const Modular<T> &rhs) { return !(lhs == rhs); }
template<typename T>
bool operator<(const Modular<T> &lhs, const Modular<T> &rhs) { return lhs.value < rhs.value; }
template<typename T>
Modular<T> operator+(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) += rhs; }
template<typename T, typename U>
Modular<T> operator+(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) += rhs; }
template<typename T, typename U>
Modular<T> operator+(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) += rhs; }
template<typename T>
Modular<T> operator-(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) -= rhs; }
template<typename T, typename U>
Modular<T> operator-(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) -= rhs; }
template<typename T, typename U>
Modular<T> operator-(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) -= rhs; }
template<typename T>
Modular<T> operator*(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) *= rhs; }
template<typename T, typename U>
Modular<T> operator*(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) *= rhs; }
template<typename T, typename U>
Modular<T> operator*(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) *= rhs; }
template<typename T>
Modular<T> operator/(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) /= rhs; }
template<typename T, typename U>
Modular<T> operator/(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) /= rhs; }
template<typename T, typename U>
Modular<T> operator/(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) /= rhs; }
template<typename T, typename U>
Modular<T> power(const Modular<T> &a, const U &b) {
assert(b >= 0);
Modular<T> x = a, res = 1;
U p = b;
while (p > 0) {
if (p & 1) res *= x;
x *= x;
p >>= 1;
}
return res;
}
template<typename T>
string to_string(const Modular<T> &number) {
return to_string(number());
}
template<typename T>
std::ostream &operator<<(std::ostream &stream, const Modular<T> &number) {
return stream << number();
}
template<typename T>
std::istream &operator>>(std::istream &stream, Modular<T> &number) {
typename common_type<typename Modular<T>::Type, int64_t>::type x;
stream >> x;
number.value = Modular<T>::normalize(x);
return stream;
}
constexpr int md = 1e9+7;
using Mint = Modular<std::integral_constant<decay<decltype(md)>::type, md>>;
}
using Ment::Mint;
const int maxn = 1e4 + 100, inf = 1e9 + 100;
int n, c[200], b[200], a[200];
Mint dp[110][maxn];
void go(int x) {
dp[0][0] = 1;
int B = 0, sb = 0;
int Cs = 0;
for (int i = 0; i < n; i++) {
for (int A = 0; A <= Cs; A++)
if (dp[i][A] != 0) {
for (int j = 0; j <= c[i]; j++) {
int na = A + j;
if (na - B >= x * (i + 1)) {
dp[i + 1][na] += dp[i][A];
}
}
}
Cs += c[i];
if (i + 1 < n) {
sb += b[i];
B += sb;
}
}
Mint ans = 0;
for (int i = 0; i <= Cs; i++)
ans += dp[n][i];
cout << ans << '\n';
}
void solve() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> c[i];
for (int i = 0; i < n - 1; i++)
cin >> b[i];
int zap;
cin >> zap;
while (zap--) {
int x;
cin >> x;
go(x);
}
}
int main() {
#ifdef ONPC
freopen("../a.in", "r", stdin);
//freopen("../a.out", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed;
cout.precision(20);
solve();
cerr << "\n\nConsumed " << TIME;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
const int MOD = (int)1e9 + 7;
inline int add(int u, int v, int mod = MOD) {
return (u += v) >= mod ? u - mod : u;
}
inline int sub(int u, int v, int mod = MOD) {
return (u -= v) < 0 ? u + mod : u;
}
inline int mul(int u, int v, int mod = MOD) { return (long long)u * v % mod; }
inline int power(int u, int v, int mod = MOD) {
int res = 1;
for (; v; v >>= 1, u = mul(u, u, mod))
if (v & 1) res = mul(res, u, mod);
return res;
}
inline int inv(int u, int mod = MOD) { return power(u, mod - 2, mod); }
inline void add_to(int &u, int v, int mod = MOD) { u = add(u, v, mod); }
inline void sub_to(int &u, int v, int mod = MOD) { u = sub(u, v, mod); }
inline void mul_to(int &u, int v, int mod = MOD) { u = mul(u, v, mod); }
int n;
int a[N];
int b[N];
int sum_b[N];
int sum_ib[N];
int q;
int x[N];
int f[N][N * N];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i < n; i++) {
cin >> b[i];
}
for (int i = 1; i < n; i++) {
sum_b[i] = sum_b[i - 1] + b[i];
sum_ib[i] = sum_ib[i - 1] + i * b[i];
}
cin >> q;
for (int i = 1; i <= q; i++) {
cin >> x[i];
}
f[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int prev_sum = 0; prev_sum < N * N; prev_sum++) {
if (f[i - 1][prev_sum]) {
for (int j = 0; j <= a[i]; j++) {
int sum = prev_sum + j;
int now = sum - sum_b[i - 1] * i + sum_ib[i - 1];
if (now >= x[1] * i) {
add_to(f[i][sum], f[i - 1][prev_sum]);
}
}
}
}
}
int res = 0;
for (int i = 0; i < N * N; i++) {
add_to(res, f[n][i]);
}
cout << res << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define RANGE(x) x.begin(),x.end()
void one(){
}
int main(){
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
vector<int> b(n-1);
vector<int> c(n);
ll allways= 1;
vector<int> cpre(n+1);
cpre[0]=0;
for(int i=0;i<n;++i){
cin>>c[i];
allways*=c[i];
cpre[i+1]=cpre[i]+c[i];
allways%=mod;
}
for(int i=1;i<n;++i){
cin>>b[i-1];
}
int Q;
//cin>>Q;
vector<int> bbars(n);
vector<int> bpre(n);
bpre[0]=0;
bbars[0]=0;
for(int i=1;i<n;++i){
bpre[i]=bpre[i-1]+b[i-1];
bbars[i]=bbars[i-1]+bpre[i];
}
vector<vector<int>> good(n);
good[0].resize(c[0]+1,1);
for(int k=1; k<n;++k){
good[k].resize(1+cpre[k+1]);
ll val = 0;
for(int i=0;i<=cpre[k+1];++i){
if(i>=c[k]+1)val-=good[k-1][i-c[k]-1];
if(i<=cpre[k])val+=good[k-1][i];
good[k][i] = val%mod;
}
}
ll curr = 0;
for(ll k : good[n-1]){
curr+=k;
}
curr%=mod;
//cout<<curr<<endl;
cin>>Q;
vector<pair<int,int>> qs(Q);
vector<int> res(Q,0);
for(int i =0 ;i<Q;++i){
int x;
cin>>x;
qs[i] = make_pair(x,i);
}
sort(RANGE(qs));
for(auto& p:qs){
int x = p.first;
// check to see if this breaks something
bool recalc=false;
for(int stop=0;stop<n;++stop){
int check = bbars[stop]+ (stop+1)*x;
// cout<<x<<" "<<stop<<" "<<check<<endl;
if(check<0)continue;
if(check>cpre[stop+1]){
//result is 0
goto allzero;
}
else if(good[stop][check]>0){
// recalculate here
recalc = true;
}
}
if(recalc){
//vector<vector<int>> good(n);
//good[0].resize(c[0]+1,1+mod);
int mi = bbars[0]+x;
for(int i=0;i<mi;++i){
good[0][i]=0;
}
for(int i=max(mi,0);i<=c[0];++i)good[0][i]=1+mod;
for(int k=1; k<n;++k){
ll val = 0;
int stop = bbars[k]+x*(k+1);
for(int i=0;i<=cpre[k+1];++i){
if(i>=c[k]+1)val-=good[k-1][i-c[k]-1];
if(i<=cpre[k])val+=good[k-1][i];
good[k][i] = val%mod + (val==0?0:mod);
}
for(int j=0;j<min(stop,cpre[k+1]+1);++j)good[k][j]=0;
}
curr = 0;
for(ll k : good[n-1]){
//cout<<k<<endl;
curr+=k;
}
curr%=mod;
}
res[p.second]=curr;
}
allzero: void(0);
for(int i=0;i<Q;++i){
cout<<res[i]<<endl;
}
cout<<flush;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 105;
const int maxm = 10005;
const int mod = 1e9 + 7;
inline int add(int x, int y) {
x += y;
return x >= mod ? x - mod : x;
}
inline int sub(int x, int y) {
x -= y;
return x < 0 ? x + mod : x;
}
inline int mul(int x, int y) {
return 1ll * x * y % mod;
}
int n, q, c[maxn], b[maxn], preb[maxn];
int _ans[maxm << 1], *ans = _ans + maxm;
int calc(int x) {
static int f[maxm], _s[maxm], *sum = _s + 1;
f[0] = 1;
int low = 0, upp = 0;
for(int i = 1; i <= n; i++) {
sum[low - 1] = 0;
for(int j = low; j <= upp; j++)
sum[j] = add(sum[j - 1], f[j]);
int st = max(0, x * i + preb[i]), ed = upp + c[i];
if(st > ed)
return 0;
for(int j = st; j <= ed; j++)
f[j] = sub(sum[min(j, upp)], sum[max(j - c[i], low) - 1]);
low = st, upp = ed;
}
int ans = 0;
for(int i = low; i <= upp; i++)
ans = add(ans, f[i]);
return ans;
}
int main() {
scanf("%d", &n);
int all = 1;
for(int i = 1; i <= n; i++)
scanf("%d", &c[i]), all = mul(all, c[i] + 1);
for(int i = 1; i < n; i++) {
scanf("%d", &b[i]);
preb[i + 1] = preb[i] + b[i];
}
for(int i = 2; i <= n; i++)
preb[i] += preb[i - 1];
int L = 0, R = 1;
ans[0] = calc(0), ans[1] = calc(1);
for(; ans[R]; R++, ans[R] = calc(R));
for(; ans[L] != all; L--, ans[L] = calc(L));
scanf("%d", &q);
for(int i = 1, x; i <= q; i++) {
scanf("%d", &x);
if(x > R)
puts("0");
else if(x < L)
printf("%d\n", all);
else
printf("%d\n", ans[x]);
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
#define sz(s) (int)s.size()
#define f first
#define s second
#define pb push_back
#define all(s) s.begin(), s.end()
#define vi vector<int>
#define vvi vector<vi>
#define ll long long
#define vll vector<ll>
#define ii pair<int, int>
#define vii vector<ii>
#define vvii vector<vii>
const int INF = 1e9 + 7;
const int mod = INF;
const int N = 1e6 + 7;
const int T = 1 << 20;
int c[N];
int b[N];
int d[N];
void solve(){
int n;
cin >> n;
for(int i = 0; i < n; i++)
cin >> c[i];
for(int i = 0; i < n - 1; i++)
cin >> b[i];
int q;
cin >> q;
int shift = 100 * 100 + 7;
for(int _ = 0; _ < q; _++){
int zap;
cin >> zap;
// policz schodki
d[0] = zap;
int last = d[0];
for(int i= 0; i < n - 1; i++){
last += b[i];
d[i + 1] = d[i] + last;
d[i + 1] = min(d[i + 1], shift - 1);
}
vi dp(shift + shift);
dp[shift] = 1;
for(int i = 0; i < n; i++){
vi dp2(shift + shift);
for(int j = 0; j <= c[i]; j++)
for(int k = 0; k < shift + shift; k++)
if(k + j < shift + shift and k + j >= d[i] + shift)
dp2[k + j] = (dp2[k + j] + dp[k]) % INF;
swap(dp, dp2);
}
int ans = 0;
for(int i = 0; i < shift + shift; i++)
ans = (ans + dp[i]) % INF;
cout << ans << '\n';
}
}
signed main(){
int test = 1;
// cin >> test;
for(int i = 0; i < test; i++)
solve();
}
|
#include<bits/stdc++.h>
using namespace std;
const int N=109,M=10009,P=1e9+7;
int s[N],c[N],b[N],f[M],g[M],n;
map<int,int>mp;
int wk(int x){
int i,j,k;
for(memset(f,0,s[n]*4+4),i=f[0]=1;i<=n;++i){
for(g[0]=f[0],j=1;j<=s[i];++j)if(g[j]=g[j-1]+f[j],g[j]>=P)g[j]-=P;
for(j=0,k=x*i+b[i];j<=s[i];++j)if(j<k)f[j]=0;else if(f[j]=g[j]-(j-c[i]<1?0:g[j-c[i]-1]),f[j]<0)f[j]+=P;
}
for(i=j=0;i<=s[n];++i)j=(j+f[i])%P;
return j;
}
int main(){
int q,i,mn=P,mx=P,ms;
for(i=1,scanf("%d",&n);i<=n;++i)scanf("%d",c+i);
for(i=2;i<=n;++i)scanf("%d",b+i),b[i]+=b[i-1];
for(i=2;i<=n;++i)b[i]+=b[i-1];
for(i=1;i<=n;++i)mn=min(mn,-b[i]/i),s[i]=s[i-1]+c[i],mx=min(mx,(s[i]-b[i])/i);
for(ms=wk(mn-=2),mx+=2,scanf("%d",&q);q--;){
scanf("%d",&i);
if(i<mn)printf("%d\n",ms);
else if(i>mx)puts("0");
else if(mp.count(i))printf("%d\n",mp[i]);
else printf("%d\n",mp[i]=wk(i));
}
return 0;
}
|
#pragma GCC optimize("-Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
// #include <atcoder/all>
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
using namespace std;
// using namespace atcoder;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<p64,p64> pp64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef pair<ll,p64> tp;
ll MOD = 1e9+7;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln '\n'
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define zero ll(0)
#define set_bits(x) __builtin_popcountll(x)
// #define mint modint998244353
ll mpow(ll a, ll b){
if(a==0) return 0;
if(b==0) return 1;
ll t1 = mpow(a,b/2);
t1 *= t1;
t1 %= MOD;
if(b%2) t1 *= a;
t1 %= MOD;
return t1;
}
ll mpow(ll a, ll b, ll p){
if(a==0) return 0;
if(b==0) return 1;
ll t1 = mpow(a,b/2,p);
t1 *= t1;
t1 %= p;
if(b%2) t1 *= a;
t1 %= p;
return t1;
}
ll modinverse(ll a, ll m){
ll m0 = m;
ll y = 0, x = 1;
if (m == 1) return 0;
while (a > 1){
ll q = a / m;
ll t = m;
m = a % m, a = t;
t = y;
y = x - q * y;
x = t;
}
if (x < 0) x += m0;
return x;
}
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
ll range(ll l, ll r){
return l + mt()%(r-l+1);
}
ll rev(ll v){
return mpow(v,MOD-2);
}
ll nc2(ll n){
return (n*(n-1))/2;
}
const ll N = 1e5+5;
void solve(){
ll n;
cin >> n;
ll c[n];
forn(i,n) cin >> c[i];
ll b[n];
b[n-1]=0;
forn(i,n-1) cin >> b[i];
rforn(i,n-2) b[i] += b[i+1];
ll ux=INF,lx;
ll sumb = 0, sumc = 0;
forn(i,n) sumb += b[i];
forn(i,n) sumc += c[i];
lx = sumb/n;
ux = (sumb+sumc)/n+1;
ll q;
cin >> q;
v64 gdp(N,-1);
ll nc = 0;
forn(i,q){
ll x;
cin >> x;
x += b[0];
if(x<lx) x = lx;
else if(x>ux) x = ux;
if(gdp[x]==-1){
nc++;
assert(nc < 200);
ll mpv = 0;
forn(i,n){
mpv += max(zero,x-b[i]);
}
mpv++;
// assert(mpv < 20000);
v64 dp(mpv+2,0);
dp[0]=1;
rforn(i,n-1){
v64 ndp(mpv+2,0);
// forn(k,mpv){
// forsn(j,b[i],b[i]+c[i]+1){
// ll nk = max(zero,k-(j-x));
// if(nk <= mpv) ndp[nk] += dp[k];
// }
// }
// forn(k,mpv){
// dp[k] = ndp[k]%MOD;
// }
forn(k,mpv){
ll r = max(zero,k-(b[i]-x)), l = max(zero,k-(b[i]+c[i]-x));
ndp[0] += (c[i]-(r-l))*dp[k];
ndp[1] -= (c[i]-(r-l))*dp[k];
r = min(r,mpv);
l = min(l,mpv);
ndp[l]+=dp[k];
ndp[r+1]-=dp[k];
}
forn(k,mpv){
if(k) {
ndp[k] += ndp[k-1];
}
ndp[k] %= MOD;
dp[k] = ndp[k];
}
}
gdp[x] = dp[0];
}
cout << (gdp[x]+MOD)%MOD << ln;
}
}
int main()
{
fast_cin();
ll t=1;
// cin >> t;
forn(i,t) {
// cout << "Case #" << i+1 << ": ";
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define debug(a) cerr << #a << ": " << (a) << '\n';
#define debug_arr(a, n) { cerr << #a << " "; rep(i, 0, n) cerr << a[i] << " \n"[(i + 1) == n]; }
#define debug_two(a, b) cerr << #a << ": " << (a) << ", " << #b << ": " << (b) << '\n';
template <typename num_t>
inline void add_mod(num_t& a, const long long& b, const int& m) { a = (a + b) % m; if (a < 0) a += m; }
template <typename num_t>
inline bool update_max(num_t& a, const num_t& b) { return a < b ? a = b, true : false; }
template <typename num_t>
inline bool update_min(num_t& a, const num_t& b) { return a > b ? a = b, true : false; }
template <typename num_t>
num_t gcd(num_t lhs, num_t rhs) { return !lhs ? rhs : gcd(rhs % lhs, lhs); }
template <typename num_t>
num_t pw(num_t n, num_t k, num_t mod) {
num_t res = 1; for (; k > 0; k >>= 1) { if (k & 1) res = 1ll * res * n % mod; n = 1ll * n * n % mod; } return res;
}
int invserse(int n, int mod) {
return pw(n, mod - 2, mod);
}
typedef long long int64;
const int mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
vector<int> c(n); rep(i, 0, n) cin >> c[i];
vector<int> b(n, 0);
rep(i, 1, n) {
cin >> b[i];
b[i] += b[i - 1];
}
vector<int> sum_b(n, 0);
rep(i, 0, n) {
sum_b[i] = b[i];
if (i) sum_b[i] += sum_b[i - 1];
}
const int base = 100000;
int q = 0; cin >> q;
while (q-- > 0) {
int x; cin >> x;
vector<int> pre, cur;
cur.assign(base * 2 + 1, 0);
rep(val, max(0, x), c[0] + 1) {
cur[val + base] = 1;
}
rep(i, 1, sz(cur)) cur[i] += cur[i - 1];
rep(i, 1, n) {
pre = cur;
fill_n(cur.begin(), sz(cur), 0);
rep(sum, 0, sz(cur)) if (sum - base - sum_b[i] >= (i + 1) * x) {
cur[sum] = pre[sum];
if (sum - c[i] - 1 >= 0) {
add_mod(cur[sum], -pre[sum - c[i] - 1], mod);
}
}
rep(sum, 1, sz(cur)) add_mod(cur[sum], cur[sum - 1], mod);
}
cout << cur.back() << '\n';
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL_
freopen("in.txt", "r", stdin);
#endif
const bool multiple_test = false;
int test = 1;
if (multiple_test)
cin >> test;
for(int i = 0; i < test; ++i) {
//printf("Case #%d: ", i + 1);
solve();
}
#ifdef _LOCAL_
cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
#endif
}
|
#include <bits/stdc++.h>
using namespace std;
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define debug(a) cerr << #a << ": " << (a) << '\n';
#define debug_arr(a, n) { cerr << #a << " "; rep(i, 0, n) cerr << a[i] << " \n"[(i + 1) == n]; }
#define debug_two(a, b) cerr << #a << ": " << (a) << ", " << #b << ": " << (b) << '\n';
template <typename num_t>
inline void add_mod(num_t& a, const long long& b, const int& m) { a = (a + b) % m; if (a < 0) a += m; }
template <typename num_t>
inline bool update_max(num_t& a, const num_t& b) { return a < b ? a = b, true : false; }
template <typename num_t>
inline bool update_min(num_t& a, const num_t& b) { return a > b ? a = b, true : false; }
template <typename num_t>
num_t gcd(num_t lhs, num_t rhs) { return !lhs ? rhs : gcd(rhs % lhs, lhs); }
template <typename num_t>
num_t pw(num_t n, num_t k, num_t mod) {
num_t res = 1; for (; k > 0; k >>= 1) { if (k & 1) res = 1ll * res * n % mod; n = 1ll * n * n % mod; } return res;
}
int invserse(int n, int mod) {
return pw(n, mod - 2, mod);
}
typedef long long int64;
const int mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
vector<int> c(n); rep(i, 0, n) cin >> c[i];
vector<int> b(n, 0);
rep(i, 1, n) {
cin >> b[i];
b[i] += b[i - 1];
}
vector<int> sum_b(n, 0);
rep(i, 0, n) {
sum_b[i] = b[i];
if (i) sum_b[i] += sum_b[i - 1];
}
const int base = 10007;
map<int, int> pre_calc;
int sum_c = accumulate(c.begin(), c.end(), 0);
// debug_two(n, mx_a - sum_b.back());
// debug(-sum_b.back() / n);
function<int(int)> get_value = [&](int x) -> int {
if (x > c[0])
return 0;
if (pre_calc.count(x))
return pre_calc[x];
if (x < 0 && sum_b.back() == 0) {
return get_value(0);
}
if (x < -sum_b.back() / n - 1) {
return get_value(-sum_b.back() / n - 1);
}
if (x < 0 && (sum_c - sum_b.back()) / n < x) {
// debug_two(x, (sum_c - sum_b.back()) / n)
return get_value((sum_c - sum_b.back()) / n);
}
vector<int> pre, cur;
cur.assign(base, 0);
rep(val, max(0, x), c[0] + 1) {
cur[val] = 1;
}
rep(i, 1, sz(cur)) cur[i] += cur[i - 1];
rep(i, 1, n) {
pre = cur;
fill(cur.begin() + max(0, i * x + sum_b[i - 1]), cur.end(), 0);
rep(sum, max(0, (i + 1) * x + sum_b[i]), sz(cur)) {
cur[sum] = pre[sum];
if (sum - c[i] - 1 >= 0) {
add_mod(cur[sum], -pre[sum - c[i] - 1], mod);
}
if (sum)
add_mod(cur[sum], cur[sum - 1], mod);
}
}
pre_calc[x] = cur.back();
return cur.back();
};
int q = 0; cin >> q;
while (q-- > 0) {
int x; cin >> x;
cout << get_value(x) << '\n';
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL_
freopen("in.txt", "r", stdin);
#endif
const bool multiple_test = false;
int test = 1;
if (multiple_test)
cin >> test;
for(int i = 0; i < test; ++i) {
//printf("Case #%d: ", i + 1);
solve();
}
#ifdef _LOCAL_
cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
#endif
}
|
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int>pi;
const int maxn=1e6+10;
const int M=1000000007;
int n,x,b[105],s[105],c[105],dp[105][10005],sum,ans,tot,q;
void add(int &x,int y){x+=y;if (x>=M)x-=M;}
void sub(int &x,int y){x-=y;if (x<0) x+=M;}
int main(){
scanf("%d",&n); tot=1;
for (int i=1;i<=n;i++) {
scanf("%d",&c[i]);
tot=1ll*tot*(c[i]+1)%M;
}
for (int i=1;i<n;i++) scanf("%d",&b[i]);
scanf("%d%d",&q,&x);
for (int i=1;i<n;i++) b[i]+=b[i-1],s[i]=s[i-1]+b[i];
dp[0][0]=1;
for (int i=1;i<=n;i++){
for (int j=0;j<=sum;j++)
for (int k=0;k<=c[i];k++)
add(dp[i][j+k],dp[i-1][j]);
sum+=c[i];
for (int j=0;j<=sum;j++){
if (j<x*i+s[i-1]) dp[i][j]=0;
}
}
ans=0;
for (int i=0;i<=sum;i++) add(ans,dp[n][i]);
printf("%d\n",ans);
return 0;
}
|
#include <bits/stdc++.h>
#define int long long
using namespace std;
// https://github.com/nweeks1/UltiSnips
template <const int32_t MOD> struct ModInt {
int32_t x;
ModInt() : x(0) {}
ModInt(long long u) : x(u) {
x %= MOD;
if (x < 0)
x += MOD;
}
friend bool operator==(const ModInt &a, const ModInt &b) {
return a.x == b.x;
}
friend bool operator!=(const ModInt &a, const ModInt &b) {
return a.x != b.x;
}
friend bool operator<(const ModInt &a, const ModInt &b) { return a.x < b.x; }
friend bool operator>(const ModInt &a, const ModInt &b) { return a.x > b.x; }
friend bool operator<=(const ModInt &a, const ModInt &b) {
return a.x <= b.x;
}
friend bool operator>=(const ModInt &a, const ModInt &b) {
return a.x >= b.x;
}
static ModInt sign(long long k) {
return ((k & 1) ? ModInt(MOD - 1) : ModInt(1));
}
ModInt &operator+=(const ModInt &m) {
x += m.x;
if (x >= MOD)
x -= MOD;
return *this;
}
ModInt &operator-=(const ModInt &m) {
x -= m.x;
if (x < 0LL)
x += MOD;
return *this;
}
ModInt &operator*=(const ModInt &m) {
x = (1LL * x * m.x) % MOD;
return *this;
}
friend ModInt operator-(const ModInt &a) {
ModInt res(a);
if (res.x)
res.x = MOD - res.x;
return res;
}
friend ModInt operator+(const ModInt &a, const ModInt &b) {
return ModInt(a) += ModInt(b);
}
friend ModInt operator-(const ModInt &a, const ModInt &b) {
return ModInt(a) -= ModInt(b);
}
friend ModInt operator*(const ModInt &a, const ModInt &b) {
return ModInt(a) *= ModInt(b);
}
static long long fp(long long u, long long k) {
long long res = 1LL;
while (k > 0LL) {
if (k & 1LL)
res = (res * u) % MOD;
u = (u * u) % MOD;
k /= 2LL;
}
return res;
}
static constexpr int mod() { return MOD; }
ModInt fastpow(long long k) { return ModInt(fp(x, k)); }
ModInt inv() {
assert(x);
return ModInt(fp(x, MOD - 2));
}
ModInt &operator/=(const ModInt &m) { return *this *= ModInt(m).inv(); }
friend ModInt operator/(const ModInt &a, const ModInt &b) {
return ModInt(a) *= ModInt(b).inv();
}
friend ostream &operator<<(ostream &out, const ModInt &a) {
return out << a.x;
}
friend istream &operator>>(istream &in, ModInt &a) { return in >> a.x; }
};
const int MOD = 1e9 + 7;
using Mint = ModInt<MOD>;
const int MAXSUM = 1e4 + 1;
const int MAXN = 101;
Mint ways[MAXN][MAXSUM];
signed main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> c(n);
vector<int> b(n - 1);
for (int i = 0; i < n; ++i)
cin >> c[i];
for (int i = 0; i < n - 1; ++i)
cin >> b[i];
vector<int> partialB(n);
for (int k0 = 0; k0 < n; ++k0)
for (int i = 0; i < k0; ++i)
partialB[k0] += (k0 - i) * b[i];
int q;
cin >> q;
int x;
cin >> x;
ways[0][0] = 1;
for (int nbPris = 1; nbPris <= n; ++nbPris)
for (int curSum = 0; curSum < MAXSUM; ++curSum) {
if (curSum < nbPris * x + partialB[nbPris - 1])
continue;
for (int v = 0; v <= c[nbPris - 1] and v <= curSum; ++v)
ways[nbPris][curSum] += ways[nbPris - 1][curSum - v];
}
Mint sol = 0;
for (int sum = 0; sum < MAXSUM; ++sum)
sol += ways[n][sum];
cout << sol << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define si(x) int(x.size())
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
return os<<"{"<<p.a<<","<<p.b<<"}";
}
template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
os<<"{";
for(auto e:v)os<<e<<",";
return os<<"}";
}
#define mp make_pair
#define mt make_tuple
#define one(x) memset(x,-1,sizeof(x))
#define zero(x) memset(x,0,sizeof(x))
#ifdef LOCAL
void dmpr(ostream&os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
os<<t<<" ";
dmpr(os,args...);
}
#define dmp2(...) dmpr(cerr,__LINE__,##__VA_ARGS__)
#else
#define dmp2(...) void(0)
#endif
using uint=unsigned;
using ull=unsigned long long;
template<class t,size_t n>
ostream& operator<<(ostream&os,const array<t,n>&a){
return os<<vc<t>(all(a));
}
template<int i,class T>
void print_tuple(ostream&,const T&){
}
template<int i,class T,class H,class ...Args>
void print_tuple(ostream&os,const T&t){
if(i)os<<",";
os<<get<i>(t);
print_tuple<i+1,T,Args...>(os,t);
}
template<class ...Args>
ostream& operator<<(ostream&os,const tuple<Args...>&t){
os<<"{";
print_tuple<0,tuple<Args...>,Args...>(os,t);
return os<<"}";
}
template<class t>
void print(t x,int suc=1){
cout<<x;
if(suc==1)
cout<<"\n";
if(suc==2)
cout<<" ";
}
ll read(){
ll i;
cin>>i;
return i;
}
vi readvi(int n,int off=0){
vi v(n);
rep(i,n)v[i]=read()+off;
return v;
}
pi readpi(int off=0){
int a,b;cin>>a>>b;
return pi(a+off,b+off);
}
template<class t,class u>
void print(const pair<t,u>&p,int suc=1){
print(p.a,2);
print(p.b,suc);
}
template<class T>
void print(const vector<T>&v,int suc=1){
rep(i,v.size())
print(v[i],i==int(v.size())-1?suc:2);
}
string readString(){
string s;
cin>>s;
return s;
}
template<class T>
T sq(const T& t){
return t*t;
}
//#define CAPITAL
void yes(bool ex=true){
#ifdef CAPITAL
cout<<"YES"<<"\n";
#else
cout<<"Yes"<<"\n";
#endif
if(ex)exit(0);
#ifdef LOCAL
cout.flush();
#endif
}
void no(bool ex=true){
#ifdef CAPITAL
cout<<"NO"<<"\n";
#else
cout<<"No"<<"\n";
#endif
if(ex)exit(0);
#ifdef LOCAL
cout.flush();
#endif
}
void possible(bool ex=true){
#ifdef CAPITAL
cout<<"POSSIBLE"<<"\n";
#else
cout<<"Possible"<<"\n";
#endif
if(ex)exit(0);
#ifdef LOCAL
cout.flush();
#endif
}
void impossible(bool ex=true){
#ifdef CAPITAL
cout<<"IMPOSSIBLE"<<"\n";
#else
cout<<"Impossible"<<"\n";
#endif
if(ex)exit(0);
#ifdef LOCAL
cout.flush();
#endif
}
constexpr ll ten(int n){
return n==0?1:ten(n-1)*10;
}
const ll infLL=LLONG_MAX/3;
#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif
int topbit(signed t){
return t==0?-1:31-__builtin_clz(t);
}
int topbit(ll t){
return t==0?-1:63-__builtin_clzll(t);
}
int botbit(signed a){
return a==0?32:__builtin_ctz(a);
}
int botbit(ll a){
return a==0?64:__builtin_ctzll(a);
}
int popcount(signed t){
return __builtin_popcount(t);
}
int popcount(ll t){
return __builtin_popcountll(t);
}
bool ispow2(int i){
return i&&(i&-i)==i;
}
ll mask(int i){
return (ll(1)<<i)-1;
}
bool inc(int a,int b,int c){
return a<=b&&b<=c;
}
template<class t> void mkuni(vc<t>&v){
sort(all(v));
v.erase(unique(all(v)),v.ed);
}
ll rand_int(ll l, ll r) { //[l, r]
#ifdef LOCAL
static mt19937_64 gen;
#else
static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
#endif
return uniform_int_distribution<ll>(l, r)(gen);
}
template<class t>
void myshuffle(vc<t>&a){
rep(i,si(a))swap(a[i],a[rand_int(0,i)]);
}
template<class t>
int lwb(const vc<t>&v,const t&a){
return lower_bound(all(v),a)-v.bg;
}
vvc<int> readGraph(int n,int m){
vvc<int> g(n);
rep(i,m){
int a,b;
cin>>a>>b;
//sc.read(a,b);
a--;b--;
g[a].pb(b);
g[b].pb(a);
}
return g;
}
vvc<int> readTree(int n){
return readGraph(n,n-1);
}
//mint107 は verify してねえ
//#define DYNAMIC_MOD
struct modinfo{uint mod,root;
#ifdef DYNAMIC_MOD
constexpr modinfo(uint m,uint r):mod(m),root(r),im(0){set_mod(m);}
ull im;
constexpr void set_mod(uint m){
mod=m;
im=ull(-1)/m+1;
}
uint product(uint a,uint b)const{
ull z=ull(a)*b;
uint x=((unsigned __int128)z*im)>>64;
uint v=uint(z)-x*mod;
return v<mod?v:v+mod;
}
#endif
};
template<modinfo const&ref>
struct modular{
static constexpr uint const &mod=ref.mod;
static modular root(){return modular(ref.root);}
uint v;
//modular(initializer_list<uint>ls):v(*ls.bg){}
modular(ll vv=0){s(vv%mod+mod);}
modular& s(uint vv){
v=vv<mod?vv:vv-mod;
return *this;
}
modular operator-()const{return modular()-*this;}
modular& operator+=(const modular&rhs){return s(v+rhs.v);}
modular&operator-=(const modular&rhs){return s(v+mod-rhs.v);}
modular&operator*=(const modular&rhs){
#ifndef DYNAMIC_MOD
v=ull(v)*rhs.v%mod;
#else
v=ref.product(v,rhs.v);
#endif
return *this;
}
modular&operator/=(const modular&rhs){return *this*=rhs.inv();}
modular operator+(const modular&rhs)const{return modular(*this)+=rhs;}
modular operator-(const modular&rhs)const{return modular(*this)-=rhs;}
modular operator*(const modular&rhs)const{return modular(*this)*=rhs;}
modular operator/(const modular&rhs)const{return modular(*this)/=rhs;}
modular pow(ll n)const{
modular res(1),x(*this);
while(n){
if(n&1)res*=x;
x*=x;
n>>=1;
}
return res;
}
modular inv()const{return pow(mod-2);}
/*modular inv()const{
int x,y;
int g=extgcd<ll>(v,mod,x,y);
assert(g==1);
if(x<0)x+=mod;
return modular(x);
}*/
friend modular operator+(int x,const modular&y){
return modular(x)+y;
}
friend modular operator-(int x,const modular&y){
return modular(x)-y;
}
friend modular operator*(int x,const modular&y){
return modular(x)*y;
}
friend modular operator/(int x,const modular&y){
return modular(x)/y;
}
friend ostream& operator<<(ostream&os,const modular&m){
return os<<m.v;
}
friend istream& operator>>(istream&is,modular&m){
ll x;is>>x;
m=modular(x);
return is;
}
bool operator<(const modular&r)const{return v<r.v;}
bool operator==(const modular&r)const{return v==r.v;}
bool operator!=(const modular&r)const{return v!=r.v;}
explicit operator bool()const{
return v;
}
};
#ifndef DYNAMIC_MOD
//extern constexpr modinfo base{998244353,3};
extern constexpr modinfo base{1000000007,0};
//modinfo base{1,0};
#ifdef USE_GOOD_MOD
static_assert(base.mod==998244353);
#endif
#else
modinfo base(1,0);
extern constexpr modinfo base107(1000000007,0);
using mint107=modular<base107>;
#endif
using mint=modular<base>;
const int vmax=(1<<21)+10;
mint fact[vmax],finv[vmax],invs[vmax];
void initfact(){
fact[0]=1;
rng(i,1,vmax){
fact[i]=fact[i-1]*i;
}
finv[vmax-1]=fact[vmax-1].inv();
for(int i=vmax-2;i>=0;i--){
finv[i]=finv[i+1]*(i+1);
}
for(int i=vmax-1;i>=1;i--){
invs[i]=finv[i]*fact[i-1];
}
}
mint choose(int n,int k){
return fact[n]*finv[n-k]*finv[k];
}
mint binom(int a,int b){
return fact[a+b]*finv[a]*finv[b];
}
mint catalan(int n){
return binom(n,n)-(n-1>=0?binom(n-1,n+1):0);
}
/*
const int vmax=110;
mint binbuf[vmax][vmax];
mint choose(int n,int k){
return binbuf[n-k][k];
}
mint binom(int a,int b){
return binbuf[a][b];
}
void initfact(){
binbuf[0][0]=1;
rep(i,vmax)rep(j,vmax){
if(i)binbuf[i][j]+=binbuf[i-1][j];
if(j)binbuf[i][j]+=binbuf[i][j-1];
}
}
*/
void slv(){
int n;cin>>n;
vi c=readvi(n);
vi b=readvi(n-1);
vi h(n);
{
int sum=0,cur=0;
rep(i,n-1){
cur+=b[i];
sum+=cur;
h[i+1]=sum;
}
}
int q;cin>>q;
rep(_,q){
int thre;cin>>thre;
int tot=accumulate(all(c),int(0))+10;
vc<mint> dp(tot);
dp[0]=1;
rep(k,n){
int v=c[k];
per(i,tot-1-v)dp[i+1+v]-=dp[i];
rep(i,tot-1)dp[i+1]+=dp[i];
int z=thre*(k+1)+h[k];
chmin(z,tot);
rep(j,z)dp[j]=0;
}
print(accumulate(all(dp),mint(0)));
}
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
cout<<fixed<<setprecision(20);
//int t;cin>>t;rep(_,t)
slv();
}
|
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
#define mod 1000000007
using namespace std;
int n,m;
int c[109],b[109];
int smb[109],ssb[109];
int f[109][10009],sf[109][10009],g[10009];
int pt[109],smc[109];
pii q[100009];
int ans[100009];
int mo(int x)
{
f[0][0]=1;
for(int i=1;i<=n;i++)
{
int mn=i*x+ssb[i-1],lp=0;
ll sm=0;
for(int j=0;j<=smc[i];j++)
{
sm+=f[i-1][j];
(lp<j-c[i])&&(sm+=mod-f[i-1][lp]);
lp+=(lp<j-c[i]);
// printf("i:%d j:%d lp:%d sm:%d\n",i,j,lp,sm);
f[i][j]=j>=mn?sm%mod:0;
}
}
int ans=0;
for(int i=0;i<=smc[n];i++)
ans=(ans+f[n][i])%mod;
return ans;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",c+i);
smc[i]=smc[i-1]+c[i];
}
for(int i=1;i<=n-1;i++)
{
scanf("%d",b+i);
smb[i]=smb[i-1]+b[i];
ssb[i]=ssb[i-1]+smb[i];
}
scanf("%d",&m);
for(int i=1;i<=m;i++)
{
scanf("%d",&q[i].fi);
q[i].se=i;
}
sort(q+1,q+m+1);
for(int k=1;k<=1000;k++)
for(int i=1;i<=m;i++)
ans[q[i].se]=mo(q[i].fi);
for(int i=1;i<=m;i++)
printf("%d\n",ans[i]);
return 0;
}
|
#include <bits/stdc++.h>
#define mp std::make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define gc getchar
#define pc putchar
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef std::pair <int, int> pii;
typedef std::pair <ll, ll> pll;
const int mod = 1000000007;
const int max_N = 107;
int n, B[max_N], C[max_N], dp[max_N][max_N * max_N];
int read_int() {
char c = gc(); int ans = 0; bool neg = false;
while (!isdigit(c)) neg |= (c == '-'), c = gc();
while (isdigit(c)) ans = 10 * ans + c - '0', c = gc();
return neg ? -ans : ans;
}
void write_int(int x) {
if (x < 0) pc('-'), x = -x;
if (x > 9) write_int(x / 10);
pc(x % 10 + '0');
}
int min(int x, int y) {return x < y ? x : y;}
int max(int x, int y) {return x > y ? x : y;}
void _min(int &x, int y) {if (x > y) x = y;}
void _max(int &x, int y) {if (x < y) x = y;}
int plus(int x, int y) {return (x += y) >= mod ? x - mod : x;}
int minus(int x, int y) {return (x -= y) < 0 ? x + mod : x;}
int mul(int x, int y) {return (ll)x * y % mod;}
int fma(int x, int y, int z) {return (x + (ll)y * z) % mod;}
int fms(int x, int y, int z) {return (x + (ll)(mod - y) * z) % mod;}
int neg(int x) {return x == 0 ? 0 : mod - x;}
void _plus(int &x, int y) {if ((x += y) >= mod) x -= mod;}
void _minus(int &x, int y) {if ((x -= y) < 0) x += mod;}
void _mul(int &x, int y) {x = (ll)x * y % mod;}
void _fma(int &x, int y, int z) {x = (x + (ll)y * z) % mod;}
void _fms(int &x, int y, int z) {x = (x + (ll)(mod - y) * z) % mod;}
void _neg(int &x) {if (x) x = mod - x;}
int query(int x) {
dp[0][0] = 1;
for (int i = 1, sum = 0; i <= n; i++) {
std::fill(dp[i], dp[i] + sum + C[i] + 1, 0);
std::partial_sum(dp[i - 1], dp[i - 1] + sum + 1, dp[i - 1], plus);
for (int j = max(x * i + B[i], 0); j <= sum + C[i]; j++) {
int l = max(j - C[i], 0), r = min(sum, j);
if (l <= r) _plus(dp[i][j], minus(dp[i - 1][r], l == 0 ? 0 : dp[i - 1][l - 1]));
}
sum += C[i];
}
return std::accumulate(dp[n], dp[n] + C[0] + 1, 0ll) % mod;
}
int main() {
n = read_int();
for (int i = 1; i <= n; i++) C[i] = read_int();
C[0] = std::accumulate(C + 1, C + n + 1, 0);
for (int i = 2; i <= n; i++) B[i] = read_int();
std::partial_sum(B + 2, B + n + 1, B + 2);
std::partial_sum(B + 2, B + n + 1, B + 2);
for (int i = read_int(); i; i--)
write_int(query(read_int())), pc('\n');
return 0;
}
|
#include <iostream>
#include <algorithm>
constexpr int N = 105;
constexpr int p = 1000000007;
int add(int x, int y) { return (x += y) >= p ? x - p : x; }
int sub(int x, int y) { return (x -= y) < 0 ? x + p : x; }
int n, q, k;
int c[N], b[N];
int f[N][N * N];
int s[2][N * N];
int l[N];
int main() {
std::ios::sync_with_stdio(false), std::cin.tie(nullptr);
std::cin >> n;
int sumc = 0;
for (int i = 1; i <= n; ++i) std::cin >> c[i], sumc += c[i];
for (int i = 1; i < n; ++i) std::cin >> b[i];
std::cin >> q;
while (q--) {
std::cin >> k;
int sumb = k;
for (int i = 1; i <= n; ++i) {
l[i] = l[i - 1] + sumb;
sumb += b[i];
}
f[0][0] = 1;
for (int i = 0; i <= sumc; ++i) s[0][i] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < l[i] && j <= sumc; ++j) s[1][j] = 0;
for (int j = std::max(l[i], 0); j <= sumc; ++j) {
f[i][j] = sub(s[0][j], j - c[i] - 1 >= 0 ? s[0][j - c[i] - 1] : 0);
s[1][j] = add(f[i][j], j > 0 ? s[1][j - 1] : 0);
}
std::swap(s[0], s[1]);
}
int min = k * n + sumb - k;
int ans = 0;
for (int i = std::max(min, 0); i <= sumc; ++i) {
ans = add(ans, f[n][i]);
}
std::cout << ans << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
#define range(x) (x).begin(),(x).end()
std::mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int sj(int n)
{
unsigned int x=rnd();
return x%n+1;
}
#define rand fst
template<typename typC> void read(register typC &x)
{
register int c=getchar(),fh=1;
while ((c<48)||(c>57))
{
if (c=='-') {c=getchar();fh=-1;break;}
c=getchar();
}
x=c^48;c=getchar();
while ((c>=48)&&(c<=57))
{
x=x*10+(c^48);
c=getchar();
}
x*=fh;
}
template<typename typC> void read(register typC *a,int num)
{
for (register int i=1;i<=num;i++) read(a[i]);
}
template<typename typC, typename... Args> void read(typC &first, Args& ... args) {
read(first);
read(args...);
}
template<typename typC> void write(register typC x)
{
if (x<0) putchar('-'),x=-x;
static int st[100];
register int tp=1;
register typC y;st[1]=x%10;x/=10;
while (x) y=x/10,st[++tp]=x-y*10,x=y;++tp;
while (--tp) putchar(st[tp]|48);
}
template<typename typC> void write(register typC *a,register int num)
{
for (register int i=1;i<=num;i++) write(a[i]),putchar(i==num?10:32);
}
template<typename typC> typC ab(register typC x)
{
if (x<0) return -x;
return x;
}
#define space(x) write(x),putchar(32)
#define enter(x) write(x),putchar(10)
const int p=1e9+7;
const db eps=1e-9;
inline void inc(register int &x,const int y)
{
if ((x+=y)>=p) x-=p;
}
inline void dec(register int &x,const int y)
{
if ((x-=y)<0) x+=p;
}
inline int ksm(register int x,register int y)
{
register int r=1;
while (y)
{
if (y&1) r=(ll)r*x%p;
x=(ll)x*x%p;
y>>=1;
}
return r;
}
priority_queue<int> ONLYYFORRCOPYY;
priority_queue<int,vector<int>,greater<int> > ONLYYFORRCOPYY__;
struct Q
{
int u,v;
Q(int a=0,int b=0):u(a),v(b){}
bool operator<(const Q &o) const {return v<o.v;}
};
const int N=1e2+2,M=2e4+20,inf=1e9;
char s[N];
int a[N],b[N],l[N],r[N],L[N],R[N],g[N][M],*f[N];
int T,n,m,i,j,k,ii,x,y,z,ans,la,ksiz,ks,q,cur;
int main()
{
//ios::sync_with_stdio(false);
cout<<setiosflags(ios::fixed)<<setprecision(15);
T=1;
read(n,r,n);read(b,n-1);
for (i=2;i<n;i++) b[i]+=b[i-1];
for (i=2;i<=n;i++) r[i]-=b[i-1],l[i]-=b[i-1];
read(q);read(q);cur=0;
for (i=1;i<=n;i++) L[i]=L[i-1]+l[i],R[i]=R[i-1]+r[i];
//for (i=1;i<=n;i++) printf("%d %d\n",l[i],r[i]);puts("");
for (i=0;i<=n;i++) cur+=l[i],f[i]=&(g[i][-cur+2]);
f[0][0]=1;
for (i=1;i<=n;i++) for (j=max(q*i,L[i]);j<=R[i];j++) for (k=l[i];k<=r[i];k++) if (j-k>=L[i-1]&&j-k<=R[i-1]) inc(f[i][j],f[i-1][j-k]);
//for (i=0;i<=n;i++) for (j=L[i];j<=R[i];j++) printf("%d %d %d\n",i,j,f[i][j]);
for (i=L[n];i<=R[n];i++) inc(ans,f[n][i]);write(ans);
}
|
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long i64;
const int N = 100 + 10, P = 1e9 + 7;
int n, b[N], c[N];
int dp[N][N * N];
int query(int x) {
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
int s = 0, sum = 0;
for(int i = 1; i <= n; i++) {
for(int j = 0; j <= s; j++) {
(dp[i][j + c[i] + 1] += P - dp[i - 1][j]) %= P;
(dp[i][j] += dp[i - 1][j]) %= P;
}
s += c[i];
for(int j = 1; j <= s; j++) {
(dp[i][j] += dp[i][j - 1]) %= P;
}
for(int j = 0; j <= s; j++) {
if(j + sum < i * x) {
dp[i][j] = 0;
}
}
sum -= b[i];
}
int ans = 0;
for(int j = 0; j <= s; j++) (ans += dp[n][j]) %= P;
return ans;
}
int main() {
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> c[i];
}
for(int i = 1; i < n; i++) {
cin >> b[i];
b[i] += b[i - 1];
}
int q, x;
cin >> q;
for(int i = 1; i <= q; i++) {
cin >> x;
cout << query(x) << endl;
}
return 0;
}
|
#include <cstdio>
#include <algorithm>
using namespace std;
#define ADD(x) ((x>=mod)?x-mod:x)
const int mod=1e9+7;
int n,c[110],b[110],sum[110],sum1[110],sumc[110],dp[110][10010],ans,Min,T,x;
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++) scanf("%d",&c[i]),sumc[i]=sumc[i-1]+c[i];
for (int i=1;i<n;i++) scanf("%d",&b[i]),sum[i]=sum[i-1]+b[i];
for (int i=1;i<=n;i++) sum1[i]=sum1[i-1]+sum[i-1];
scanf("%d%d",&T,&x);
dp[0][0]=1;
for (int i=1;i<=n;i++)
for (int j=x*i+sum1[i];j<=sumc[i];j++)
for (int k=min(j,c[i]);k>=0;k--)
dp[i][j]=ADD(dp[i][j]+dp[i-1][j-k]);
for (int i=0;i<=sumc[n];i++) ans=ADD(ans+dp[n][i]);
printf("%d\n",ans);
return 0;
}
|
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
#define mod 1000000007
using namespace std;
int n,m;
int c[109],b[109];
int smb[109],ssb[109];
int f[109][10009],g[10009];
int pt[109],smc[109];
pii q[100009];
int ans[100009];
void dp()
{
f[0][0]=1;
for(int i=1;i<=n;i++)
{
smc[i]=smc[i-1]+c[i];
for(int j=0;j<=smc[i];j++)
{
for(int k=0;k<=min(j,c[i]);k++)
f[i][j]=(f[i][j]+f[i-1][j-k])%mod;
}
}
}
int mo(int x)
{
memset(f,0,sizeof(f));
f[0][0]=1;
for(int i=1;i<=n;i++)
{
int mn=i*x+ssb[i-1];
for(int j=max(0,mn);j<=smc[i];j++)
{
for(int k=0;k<=min(j,c[i]);k++)
f[i][j]=(f[i][j]+f[i-1][j-k])%mod;
}
}
int ans=0;
for(int i=0;i<=smc[n];i++)
ans=(ans+f[n][i])%mod;
return ans;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",c+i);
for(int i=1;i<=n-1;i++)
{
scanf("%d",b+i);
smb[i]=smb[i-1]+b[i];
ssb[i]=ssb[i-1]+smb[i];
}
scanf("%d",&m);
for(int i=1;i<=m;i++)
{
scanf("%d",&q[i].fi);
q[i].se=i;
}
sort(q+1,q+m+1);
dp();
for(int i=1;i<=m;i++)
ans[q[i].se]=mo(q[i].fi);
for(int i=1;i<=m;i++)
printf("%d\n",ans[i]);
return 0;
}
|
#include <bits/stdc++.h>
#define mp std::make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define gc getchar
#define pc putchar
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef std::pair <int, int> pii;
typedef std::pair <ll, ll> pll;
const int mod = 1000000007;
const int max_N = 107;
int n, B[max_N], C[max_N], dp[max_N][max_N * max_N];
int read_int() {
char c = gc(); int ans = 0; bool neg = false;
while (!isdigit(c)) neg |= (c == '-'), c = gc();
while (isdigit(c)) ans = 10 * ans + c - '0', c = gc();
return neg ? -ans : ans;
}
void write_int(int x) {
if (x < 0) pc('-'), x = -x;
if (x > 9) write_int(x / 10);
pc(x % 10 + '0');
}
int min(int x, int y) {return x < y ? x : y;}
int max(int x, int y) {return x > y ? x : y;}
void _min(int &x, int y) {if (x > y) x = y;}
void _max(int &x, int y) {if (x < y) x = y;}
int plus(int x, int y) {return (x += y) >= mod ? x - mod : x;}
int minus(int x, int y) {return (x -= y) < 0 ? x + mod : x;}
int mul(int x, int y) {return (ll)x * y % mod;}
int fma(int x, int y, int z) {return (x + (ll)y * z) % mod;}
int fms(int x, int y, int z) {return (x + (ll)(mod - y) * z) % mod;}
int neg(int x) {return x == 0 ? 0 : mod - x;}
void _plus(int &x, int y) {if ((x += y) >= mod) x -= mod;}
void _minus(int &x, int y) {if ((x -= y) < 0) x += mod;}
void _mul(int &x, int y) {x = (ll)x * y % mod;}
void _fma(int &x, int y, int z) {x = (x + (ll)y * z) % mod;}
void _fms(int &x, int y, int z) {x = (x + (ll)(mod - y) * z) % mod;}
void _neg(int &x) {if (x) x = mod - x;}
int query(int x) {
dp[0][0] = 1;
for (int i = 1, sum = 0; i <= n; i++) {
std::fill(dp[i], dp[i] + sum + C[i] + 1, 0);
for (int j = 0; j <= sum; j++)
for (int k = 0; k <= C[i]; k++)
if (j + k - B[i] >= x * i) _plus(dp[i][j + k], dp[i - 1][j]);
sum += C[i];
}
return std::accumulate(dp[n], dp[n] + C[0] + 1, 0ll) % mod;
}
int main() {
n = read_int();
for (int i = 1; i <= n; i++) C[i] = read_int();
C[0] = std::accumulate(C + 1, C + n + 1, 0);
for (int i = 2; i <= n; i++) B[i] = read_int();
std::partial_sum(B + 2, B + n + 1, B + 2);
std::partial_sum(B + 2, B + n + 1, B + 2);
for (int i = read_int(); i; i--)
write_int(query(read_int())), pc('\n');
return 0;
}
|
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("inline")
#include<bits/stdc++.h>
using namespace std;
#define MD (1000000007U)
template<class T> struct cLtraits_identity{
using type = T;
}
;
template<class T> using cLtraits_try_make_signed =
typename conditional<
is_integral<T>::value,
make_signed<T>,
cLtraits_identity<T>
>::type;
void*wmem;
char memarr[96000000];
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
(*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
(*arr)=(T*)(*mem);
(*mem)=((*arr)+x);
}
template<class T> inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){
walloc1d(arr, x2-x1, mem);
(*arr) -= x1;
}
struct Modint{
unsigned val;
Modint(){
val=0;
}
Modint(int a){
val = ord(a);
}
Modint(unsigned a){
val = ord(a);
}
Modint(long long a){
val = ord(a);
}
Modint(unsigned long long a){
val = ord(a);
}
inline unsigned ord(unsigned a){
return a%MD;
}
inline unsigned ord(int a){
a %= (int)MD;
if(a < 0){
a += MD;
}
return a;
}
inline unsigned ord(unsigned long long a){
return a%MD;
}
inline unsigned ord(long long a){
a %= (int)MD;
if(a < 0){
a += MD;
}
return a;
}
inline unsigned get(){
return val;
}
inline Modint &operator++(){
val++;
if(val >= MD){
val -= MD;
}
return *this;
}
inline Modint &operator--(){
if(val == 0){
val = MD - 1;
}
else{
--val;
}
return *this;
}
inline Modint operator++(int a){
Modint res(*this);
val++;
if(val >= MD){
val -= MD;
}
return res;
}
inline Modint operator--(int a){
Modint res(*this);
if(val == 0){
val = MD - 1;
}
else{
--val;
}
return res;
}
inline Modint &operator+=(Modint a){
val += a.val;
if(val >= MD){
val -= MD;
}
return *this;
}
inline Modint &operator-=(Modint a){
if(val < a.val){
val = val + MD - a.val;
}
else{
val -= a.val;
}
return *this;
}
inline Modint &operator*=(Modint a){
val = ((unsigned long long)val*a.val)%MD;
return *this;
}
inline Modint &operator/=(Modint a){
return *this *= a.inverse();
}
inline Modint operator+(Modint a){
return Modint(*this)+=a;
}
inline Modint operator-(Modint a){
return Modint(*this)-=a;
}
inline Modint operator*(Modint a){
return Modint(*this)*=a;
}
inline Modint operator/(Modint a){
return Modint(*this)/=a;
}
inline Modint operator+(int a){
return Modint(*this)+=Modint(a);
}
inline Modint operator-(int a){
return Modint(*this)-=Modint(a);
}
inline Modint operator*(int a){
return Modint(*this)*=Modint(a);
}
inline Modint operator/(int a){
return Modint(*this)/=Modint(a);
}
inline Modint operator+(long long a){
return Modint(*this)+=Modint(a);
}
inline Modint operator-(long long a){
return Modint(*this)-=Modint(a);
}
inline Modint operator*(long long a){
return Modint(*this)*=Modint(a);
}
inline Modint operator/(long long a){
return Modint(*this)/=Modint(a);
}
inline Modint operator-(void){
Modint res;
if(val){
res.val=MD-val;
}
else{
res.val=0;
}
return res;
}
inline operator bool(void){
return val!=0;
}
inline operator int(void){
return get();
}
inline operator long long(void){
return get();
}
inline Modint inverse(){
int a = val;
int b = MD;
int u = 1;
int v = 0;
int t;
Modint res;
while(b){
t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
if(u < 0){
u += MD;
}
res.val = u;
return res;
}
inline Modint pw(unsigned long long b){
Modint a(*this);
Modint res;
res.val = 1;
while(b){
if(b&1){
res *= a;
}
b >>= 1;
a *= a;
}
return res;
}
inline bool operator==(int a){
return ord(a)==val;
}
inline bool operator!=(int a){
return ord(a)!=val;
}
}
;
inline Modint operator+(int a, Modint b){
return Modint(a)+=b;
}
inline Modint operator-(int a, Modint b){
return Modint(a)-=b;
}
inline Modint operator*(int a, Modint b){
return Modint(a)*=b;
}
inline Modint operator/(int a, Modint b){
return Modint(a)/=b;
}
inline Modint operator+(long long a, Modint b){
return Modint(a)+=b;
}
inline Modint operator-(long long a, Modint b){
return Modint(a)-=b;
}
inline Modint operator*(long long a, Modint b){
return Modint(a)*=b;
}
inline Modint operator/(long long a, Modint b){
return Modint(a)/=b;
}
inline int my_getchar(){
static char buf[1048576];
static int s = 1048576;
static int e = 1048576;
if(s == e && e == 1048576){
e = fread(buf, 1, 1048576, stdin);
s = 0;
}
if(s == e){
return EOF;
}
return buf[s++];
}
inline void rd(int &x){
int k;
int m=0;
x=0;
for(;;){
k = my_getchar();
if(k=='-'){
m=1;
break;
}
if('0'<=k&&k<='9'){
x=k-'0';
break;
}
}
for(;;){
k = my_getchar();
if(k<'0'||k>'9'){
break;
}
x=x*10+k-'0';
}
if(m){
x=-x;
}
}
struct MY_WRITER{
char buf[1048576];
int s;
int e;
MY_WRITER(){
s = 0;
e = 1048576;
}
~MY_WRITER(){
if(s){
fwrite(buf, 1, s, stdout);
}
}
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar(int a){
if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
fwrite(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
MY_WRITER_VAR.s = 0;
}
MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
my_putchar(a);
}
inline void wt_L(int x){
int s=0;
int m=0;
char f[10];
if(x<0){
m=1;
x=-x;
}
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
if(m){
my_putchar('-');
}
while(s--){
my_putchar(f[s]+'0');
}
}
inline void wt_L(unsigned x){
int s=0;
char f[10];
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
while(s--){
my_putchar(f[s]+'0');
}
}
inline void wt_L(long long x){
int s=0;
int m=0;
char f[20];
if(x<0){
m=1;
x=-x;
}
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
if(m){
my_putchar('-');
}
while(s--){
my_putchar(f[s]+'0');
}
}
inline void wt_L(unsigned long long x){
int s=0;
char f[21];
while(x){
f[s++]=x%10;
x/=10;
}
if(!s){
f[s++]=0;
}
while(s--){
my_putchar(f[s]+'0');
}
}
inline void wt_L(Modint x){
int i;
i = (int)x;
wt_L(i);
}
int WRITER_DOUBLE_DIGIT = 15;
inline int writerDigit_double(){
return WRITER_DOUBLE_DIGIT;
}
inline void writerDigit_double(int d){
WRITER_DOUBLE_DIGIT = d;
}
inline void wt_L(double x){
const int d = WRITER_DOUBLE_DIGIT;
int k;
int r;
double v;
if(x!=x || (x==x+1 && x==2*x)){
my_putchar('E');
my_putchar('r');
my_putchar('r');
return;
}
if(x < 0){
my_putchar('-');
x = -x;
}
x += 0.5 * pow(0.1, d);
r = 0;
v = 1;
while(x >= 10*v){
v *= 10;
r++;
}
while(r >= 0){
r--;
k = floor(x / v);
if(k >= 10){
k = 9;
}
if(k <= -1){
k = 0;
}
x -= k * v;
v *= 0.1;
my_putchar(k + '0');
}
if(d > 0){
my_putchar('.');
v = 1;
for(r=(0);r<(d);r++){
v *= 0.1;
k = floor(x / v);
if(k >= 10){
k = 9;
}
if(k <= -1){
k = 0;
}
x -= k * v;
my_putchar(k + '0');
}
}
}
inline void wt_L(const char c[]){
int i=0;
for(i=0;c[i]!='\0';i++){
my_putchar(c[i]);
}
}
inline void wt_L(string &x){
int i=0;
for(i=0;x[i]!='\0';i++){
my_putchar(x[i]);
}
}
template<class T> struct Arr1d{
int n;
int mem;
T*d;
T& operator[](int a){
return d[a];
}
void sort(){
reset();
std::sort(d, d+n);
}
int set_cumulative_sum;
int cumulative_sum_mem;
T*cumulative_sum;
void setSum(void){
int i;
set_cumulative_sum = 1;
if(cumulative_sum_mem < n+1){
delete[] cumulative_sum;
cumulative_sum = new T[n+1];
cumulative_sum_mem = n+1;
}
cumulative_sum[0] = 0;
for(i=(0);i<(n);i++){
cumulative_sum[i+1] = cumulative_sum[i] + d[i];
}
}
T getSum(int i, int j){
if(set_cumulative_sum==0){
setSum();
}
return cumulative_sum[j+1] - cumulative_sum[i];
}
void reset(){
set_cumulative_sum = 0;
}
void constructor(){
n = mem = 0;
d = NULL;
set_cumulative_sum = 0;
cumulative_sum_mem = 0;
cumulative_sum = NULL;
}
void destructor(){
delete[] d;
d = NULL;
mem = n = 0;
set_cumulative_sum = 0;
cumulative_sum_mem = 0;
delete[] cumulative_sum;
cumulative_sum = NULL;
}
void constructor(int nn){
constructor();
malloc(nn);
}
void memory_expand(int nn){
if(mem < nn){
delete[] d;
d = new T[nn];
mem = nn;
}
}
void malloc(int nn){
reset();
memory_expand(nn);
n = nn;
}
void setN(int nn){
reset();
memory_expand(nn);
n = nn;
}
void setN(int nn, T val){
int i;
reset();
memory_expand(nn);
n = nn;
for(i=(0);i<(n);i++){
d[i] = val;
}
}
void set(vector<T> &a){
int i;
int nn = a.size();
setN(nn);
for(i=(0);i<(nn);i++){
d[i] = a[i];
}
}
void set(int nn, T a[]){
int i;
setN(nn);
for(i=(0);i<(nn);i++){
d[i] = a[i];
}
}
void free(){
destructor();
}
Arr1d(){
constructor();
}
Arr1d(int nn){
constructor(nn);
}
~Arr1d(){
destructor();
}
}
;
int N;
int Q;
int X;
Arr1d<int> C;
Arr1d<int> B;
Modint dp[20001];
Modint nx[20001];
int main(){
int FmcKpFmN;
wmem = memarr;
int lm;
rd(N);
C.malloc(N);
{
int Lj4PdHRW;
for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
rd(C[Lj4PdHRW]);
}
}
B.malloc(N-1);
{
int e98WHCEY;
for(e98WHCEY=(0);e98WHCEY<(N-1);e98WHCEY++){
rd(B[e98WHCEY]);
}
}
rd(Q);
int xr20shxY = Q;
for(FmcKpFmN=(0);FmcKpFmN<(xr20shxY);FmcKpFmN++){
int i, k;
rd(X);
lm = 0;
for(i=(0);i<(20000+1);i++){
dp[i] = 0;
}
dp[0] = 1;
for(k=(0);k<(N);k++){
for(i=(0);i<(20000+1);i++){
nx[i] = 0;
}
for(i=(0);i<(20000+1);i++){
if(dp[i]){
int j;
for(j=(0);j<(C[k]+1);j++){
nx[i+j] += dp[i];
}
}
}
for(i=(0);i<(20000+1);i++){
dp[i] = nx[i];
}
lm += X + B.getSum(0, k-1);
if(lm > 20000){
lm = 20000;
}
for(i=(0);i<(lm);i++){
dp[i] = 0;
}
}
int jPV_0s1p;
cLtraits_try_make_signed<remove_reference<decltype((*((Modint*)NULL)))>::type>::type BUotOFBp;
if(20000==0){
BUotOFBp = 0;
}
else{
BUotOFBp = dp[0];
for(jPV_0s1p=(1);jPV_0s1p<(20000);jPV_0s1p++){
BUotOFBp += dp[jPV_0s1p];
}
}
wt_L(BUotOFBp);
wt_L('\n');
}
return 0;
}
// cLay version 20210619-1 [beta]
// --- original code ---
// //no-unlocked
// int N, Q, X;
// Arr1d<int> C, B;
// Modint dp[20001], nx[20001];
// {
// int lm;
// rd(N,C(N),B(N-1),Q);
// REP(Q){
// rd(X);
// lm = 0;
// rep(i,2d4+1) dp[i] = 0;
// dp[0] = 1;
// rep(k,N){
// rep(i,2d4+1) nx[i] = 0;
// rep(i,2d4+1) if(dp[i]) rep(j,C[k]+1) nx[i+j] += dp[i];
// rep(i,2d4+1) dp[i] = nx[i];
// lm += X + B.getSum(0, k-1);
// if(lm > 2d4) lm = 2d4;
// rep(i,lm) dp[i] = 0;
// }
// wt(sum(dp(2d4)));
// }
// }
|
#include <bits/stdc++.h>
using namespace std;
const int md=1000000007,MID=111*111;
int n,q,x,i,ii,i1,j,lst,len,lensum,cur,r,b[111],c[111];
long long f[2][MID];
int main() {
scanf("%d",&n);
for (i=1; i<=n; i++) scanf("%d",&c[i]);
for (i=1; i<n; i++) scanf("%d",&b[i]);
scanf("%d",&q);
while (q--) {
scanf("%d",&x);
if (x>c[1]) { puts("0"); continue; }
cur=len=0;
f[0][0]=1;
for (i=1; i<=n; i++) {
ii=i&1; i1=1-ii;
cur+=c[i];
for (j=0; j<=cur; j++) for (f[ii][j]=lst=0; lst<=j && lst<=c[i]; lst++) if (f[i1][j-lst]) {
if (x*i+lensum<=j) f[ii][j]=(f[ii][j]+f[i1][j-lst])%md;
}
len+=b[i];
lensum+=len;
}
for (j=0; j<=cur; j++) r=(r+f[n&1][j])%md;
printf("%d\n",r);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9+7;
int N, Q;
ll C[110], CS[110];
ll B[110];
ll T[110];
ll X[100100];
ll D[110][10100];
ll solve(ll X) {
memset(D,0,sizeof(D));
D[0][0] = 1;
ll base = 0;
for (int i=0;i<N;i++) {
for (ll j=max(-base, 0LL);j<=CS[i];j++) {
for (int k=0;k<=C[i+1];k++) {
D[i+1][j+k] = (D[i+1][j+k]+D[i][j])%MOD;
}
}
base -= T[i]+X;
}
ll ans = 0;
for (ll j=max(-base,0LL);j<=CS[N];j++) ans = (ans+D[N][j])%MOD;
return ans;
}
int main () {
scanf("%d",&N);
for (int i=1;i<=N;i++) scanf("%lld",&C[i]);
for (int i=1;i<=N;i++) CS[i] = CS[i-1]+C[i];
for (int i=1;i<=N-1;i++) scanf("%lld",&B[i]);
for (int i=1;i<=N-1;i++) T[i] = T[i-1]+B[i];
scanf("%d",&Q);
for (int i=0;i<Q;i++) scanf("%lld",&X[i]);
for (int i=0;i<Q;i++) {
printf("%lld\n",solve(X[i]));
}
return 0;
}
|
#include <iostream>
#include <cstdio>
#define maxn 105
using namespace std;
const int mo = 1e9 + 7;
int n, f[maxn][maxn * maxn];
int b[maxn], c[maxn], q, x;
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
for (int i = 1; i < n; i++) scanf("%d", &b[i]);
scanf("%d", &q);
scanf("%d", &x);
f[0][0] = 1;
int ans = 0;
for (int i = 1; i <= n; i++)
{
int t = i * x;
for (int j = 1; j < i; j++) t += b[j] * (i - j);
// printf("%d ", t);
for (int j = max(0, t); j <= n * 100; j++)
{
for (int k = 0; k <= c[i]; k++)
{
if(j - k >= 0) f[i][j] = (f[i][j] + f[i - 1][j - k]) % mo;
}
if(i == n) ans = (ans + f[i][j]) % mo;
}
}
printf("%d", ans);
return 0;
}
|
#include <bits/stdc++.h>
const int N = 105, M = 3e6 + 10, offset = 1.5e6 + 5, P = 1e9 + 7;
int n, c[N], b[N], f[M], g[M], Q, x;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &c[i]);
for (int i = 1; i < n; i++)
scanf("%d", &b[i]);
scanf("%d%d", &Q, &x);
int mx = c[1], mn = x;
if (mx < 0) { puts("0"); return 0; }
for (int i = std::max(0, mn); i <= mx; i++)
f[i + offset] = 1;
// for (int j = mn; j <= mx; j++)
// printf("[%d]%d ", j, f[j + offset]);
// puts("");
int sum = 0;
for (int i = 1; i < n; i++) {
sum += b[i];
// delta = a - sum \in [i * b[i], c[i + 1] + i * b[i]]
// f[i + delta] <- f[i]
// f[j] <- f[j - delta] j - delta \in [j - i * b[i] - c[i + 1], j - i * b[i]]
memset(g, 0, sizeof g);
mx += c[i + 1] + i * b[i]; mn = std::max(-(int)1e6, (i + 1) * (x + sum));
for (int j = mn - i * b[i] - c[i + 1] - 1; j <= mx - i * b[i]; j++)
g[j + offset] = (g[j - 1 + offset] + f[j + offset]) % P;
memset(f, 0, sizeof f);
for (int j = mn; j <= mx; j++)
f[j + offset] = (g[j - i * b[i] + offset] - g[j - i * b[i] - c[i + 1] - 1 + offset] + P) % P;
// for (int j = mn; j <= mx; j++)
// printf("[%d]%d ", j, f[j + offset]);
// puts("");
}
int ans = 0;
for (int i = n * (x + sum); i <= 1.5e6; i++)
ans = (ans + f[i + offset]) % P;
printf("%d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
#define all(a) begin(a), end(a)
#define forn(i, n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
const int N = 103;
const int SUM = 101 * 101;
int dp[N][SUM];
int n, a[N], b[N];
int pb[N];
void solve() {
// for all i sum - ((i-1)*b_1 + .. +b_{i-1}) >= x * i
cin >> n;
forn(i, n) {
cin >> a[i];
}
pb[0] = 0;
forn(i, n - 1) {
cin >> b[i];
pb[i + 1] = pb[i] + b[i];
}
for (int i = 1; i < n; ++i) {
pb[i] += pb[i - 1];
}
int x;
cin >> x >> x;
forn(i, a[0] + 1) {
dp[0][i] = 1;
}
forn(i, n - 1) {
ll val = 1ll * (i + 1) * x + pb[i];
val = max(val, 0ll);
for (int j = val; j < SUM; ++j) {
if (dp[i][j] == 0) continue;
for (int nxt = 0; nxt <= a[i + 1]; ++nxt) {
dp[i + 1][j + nxt] = (dp[i + 1][j + nxt] + dp[i][j]) % MOD;
}
}
}
int res = 0;
ll lower = 1ll * n * x + pb[n - 1];
lower = max(lower, 0ll);
for (int i = lower; i < SUM; ++i) res = (res + dp[n - 1][i]) % MOD;
cout << res << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
|
#include <bits/stdc++.h>
#define maxn 105
#define maxN 10086
using namespace std;
const int p = 1e9 + 7;
int n, q, x;
int b[maxn], c[maxn], f[maxN], g[maxN], sb[maxn];
int cal(int x){
for(int i = 0;i < maxN;i++) g[i] = 1;
for(int i = 1;i <= n;i++){
for(int j = 0;j < maxN;j++) f[j] = 0;
for(int j = max(0, i * x + sb[i]);j < maxN;j++) f[j] = (g[j] + p - (j - c[i] - 1 >= 0 ? g[j - c[i] - 1] : 0)) % p;
for(int j = 0;j < maxN;j++) g[j] = (f[j] + (j ? g[j - 1] : 0)) % p, f[j] = 0;
}
return g[maxN - 1];
}
map<int, int> mp;
int main(){
scanf("%d", &n);
int sum = 1;
for(int i = 1;i <= n;i++) scanf("%d", &c[i]), sum = 1ll * sum * (c[i] + 1) % p;
for(int i = 1;i < n;i++) scanf("%d", &b[i]);
for(int i = 2;i <= n;i++) for(int j = 1;j < i;j++) sb[i] += (i - j) * b[j];
int l = -((sb[n] + n - 1) / n), r = (n * maxn - sb[n] + n - 1) / n;
for(int i = l;i <= r;i++) mp[i] = cal(i);
scanf("%d", &q);
while(q--){
scanf("%d", &x);
if(x < l) printf("%d\n", sum);
else if(x > r) puts("0");
else printf("%d\n", mp[x]);
}
}
|
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)
template<unsigned MOD_> struct ModInt {
static constexpr unsigned MOD = MOD_;
unsigned x;
void undef() { x = (unsigned)-1; }
bool isnan() const { return x == (unsigned)-1; }
inline int geti() const { return (int)x; }
ModInt() { x = 0; }
ModInt(int y) { if (y<0 || (int)MOD<=y) y %= (int)MOD; if (y<0) y += MOD; x=y; }
ModInt(unsigned y) { if (MOD<=y) x = y % MOD; else x = y; }
ModInt(long long y) { if (y<0 || MOD<=y) y %= MOD; if (y<0) y += MOD; x=y; }
ModInt(unsigned long long y) { if (MOD<=y) x = y % MOD; else x = y; }
ModInt &operator+=(const ModInt y) { if ((x += y.x) >= MOD) x -= MOD; return *this; }
ModInt &operator-=(const ModInt y) { if ((x -= y.x) & (1u<<31)) x += MOD; return *this; }
ModInt &operator*=(const ModInt y) { x = (unsigned long long)x * y.x % MOD; return *this; }
ModInt &operator/=(const ModInt y) { x = (unsigned long long)x * y.inv().x % MOD; return *this; }
ModInt operator-() const { return (x ? MOD-x: 0); }
ModInt inv() const { return pow(MOD-2); }
ModInt pow(long long y) const {
ModInt b = *this, r = 1;
if (y < 0) { b = b.inv(); y = -y; }
for (; y; y>>=1) {
if (y&1) r *= b;
b *= b;
}
return r;
}
friend ModInt operator+(ModInt x, const ModInt y) { return x += y; }
friend ModInt operator-(ModInt x, const ModInt y) { return x -= y; }
friend ModInt operator*(ModInt x, const ModInt y) { return x *= y; }
friend ModInt operator/(ModInt x, const ModInt y) { return x *= y.inv(); }
friend bool operator<(const ModInt x, const ModInt y) { return x.x < y.x; }
friend bool operator==(const ModInt x, const ModInt y) { return x.x == y.x; }
friend bool operator!=(const ModInt x, const ModInt y) { return x.x != y.x; }
};
constexpr LL MOD = 1000000007;
using Mint = ModInt<MOD>;
int N;
int C[111];
int B[111];
int Q;
LL sums[111];
LL sums2[111];
Mint dp[101][10011];
void MAIN() {
scanf("%d", &N);
REP (i, N) scanf("%d", C+i);
REP (i, N-1) scanf("%d", B+i);
REP (i, N-1) sums[i+1] = sums[i] + B[i];
LL total = 0;
REP (i, N) total += sums[i];
REP (i, N) sums2[i+1] = sums2[i] + sums[i];
// rprintf("%lld", sums, sums+N+1);
// rprintf("%lld", sums2, sums2+N+1);
scanf("%d", &Q);
REP ($, Q) {
LL X;
scanf("%lld", &X);
memset(dp, 0, sizeof dp);
for (LL a=max(0LL, X); a<=C[0]; a++) {
dp[1][a] = 1;
}
for (int i=1; i<N; i++) REP (s, 100*i+1) if (dp[i][s].x) {
int len = i + 1;
REP (a, C[i]+1) {
// X <= (a + s - sums2[len]) / len;
if (X * len <= a + s - sums2[len]) {
dp[i+1][a+s] += dp[i][s];
}
}
}
Mint ans = 0;
REP (s, 100*N+1) {
ans += dp[N][s];
}
printf("%d\n", ans.geti());
}
}
int main() {
int TC = 1;
// scanf("%d", &TC);
REP (tc, TC) MAIN();
return 0;
}
|
#include <iostream>
#include <algorithm>
constexpr int N = 105;
constexpr int p = 1000000007;
int add(int x, int y) { return (x += y) >= p ? x - p : x; }
int sub(int x, int y) { return (x -= y) < 0 ? x + p : x; }
int n, q, k;
int c[N], b[N];
int f[N][N * N];
int s[2][N * N];
int l[N];
int main() {
std::ios::sync_with_stdio(false), std::cin.tie(nullptr);
std::cin >> n;
int sumc = 0;
for (int i = 1; i <= n; ++i) std::cin >> c[i], sumc += c[i];
for (int i = 1; i < n; ++i) std::cin >> b[i];
std::cin >> q;
while (q--) {
std::cin >> k;
int sumb = k;
for (int i = 1; i <= n; ++i) {
l[i] = l[i - 1] + sumb;
sumb += b[i];
}
f[0][0] = 1;
for (int i = 0; i <= sumc; ++i) s[0][i] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < l[i] && j <= sumc; ++j) s[1][j] = 0, f[i][j] = 0;
for (int j = std::max(l[i], 0); j <= sumc; ++j) {
f[i][j] = sub(s[0][j], j - c[i] - 1 >= 0 ? s[0][j - c[i] - 1] : 0);
s[1][j] = add(f[i][j], j > 0 ? s[1][j - 1] : 0);
}
std::swap(s[0], s[1]);
}
int min = k * n + sumb - k;
int ans = 0;
for (int i = std::max(min, 0); i <= sumc; ++i) {
ans = add(ans, f[n][i]);
}
std::cout << ans << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
int n, x, ans, a[105], b[105], c[105], s1[105], s2[105], dp[105][10005];
int main(){
scanf("%d", &n);
for(int i=1; i<=n; ++i){
scanf("%d", &c[i]);
s1[i] = s1[i-1] + c[i];
}
for(int i=1, s=0; i<n; ++i) scanf("%d", &b[i]);
scanf("%*d%d", &x);
s2[1] = x;
for(int i=1, s=x; i<n; ++i){
s += b[i];
s2[i+1] = s2[i] + s;
}
dp[0][0] = 1;
for(int i=0; i<n; ++i){
for(int j=0; j<=s1[i]; ++j){
for(int k=max(0, s2[i+1]-j); k<=c[i+1]; ++k){
dp[i+1][j+k] = (dp[i+1][j+k]+dp[i][j]) % Mod;
}
}
}
for(int i=max(0, s2[n]); i<=s1[n]; ++i) ans = (ans+dp[n][i]) % Mod;
printf("%d\n", ans);
return 0;
}
|
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
#define mod 1000000007
using namespace std;
int n,m;
int c[109],b[109];
int smb[109],ssb[109];
int f[109][10009],sf[109][10009],g[10009];
int pt[109],smc[109];
pii q[100009];
int ans[100009];
int mo(int x)
{
f[0][0]=1;
for(int i=1;i<=n;i++)
{
int mn=i*x+ssb[i-1],lp=0,sm=0;
for(int j=0;j<=smc[i];j++)
{
(sm+=f[i-1][j])%=mod;
if(lp<j-c[i])
{
(sm+=mod-f[i-1][lp])%=mod;
lp++;
}
// printf("i:%d j:%d lp:%d sm:%d\n",i,j,lp,sm);
f[i][j]=j>=mn?sm:0;
}
}
int ans=0;
for(int i=0;i<=smc[n];i++)
ans=(ans+f[n][i])%mod;
return ans;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",c+i);
smc[i]=smc[i-1]+c[i];
}
for(int i=1;i<=n-1;i++)
{
scanf("%d",b+i);
smb[i]=smb[i-1]+b[i];
ssb[i]=ssb[i-1]+smb[i];
}
scanf("%d",&m);
for(int i=1;i<=m;i++)
{
scanf("%d",&q[i].fi);
q[i].se=i;
}
sort(q+1,q+m+1);
for(int i=1;i<=m;i++)
ans[q[i].se]=mo(q[i].fi);
for(int i=1;i<=m;i++)
printf("%d\n",ans[i]);
return 0;
}
|
#pragma comment(linker, "/STACK:512000000")
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <deque>
#include <memory>
#include <chrono>
#include <cassert>
#include <random>
#include <queue>
#include <set>
#include <map>
#include <array>
using namespace std;
#define all(a) a.begin(), a.end()
using li = long long;
using ld = long double;
void solve(bool);
void precalc();
clock_t start;
int main() {
#ifdef AIM
freopen("/Users/alexandero/CLionProjects/cryptozoology/input.txt", "r", stdin);
//freopen("/Users/alexandero/CLionProjects/cryptozoology/output.txt", "w", stdout);
#endif
start = clock();
int t = 1;
#ifndef AIM
cout.sync_with_stdio(0);
cin.tie(0);
#endif
cout.precision(20);
cout << fixed;
//cin >> t;
precalc();
int test_num = 1;
while (t--) {
//cout << "Case #" << test_num++ << ": ";
solve(true);
}
cout.flush();
#ifdef AIM1
while (true) {
solve(false);
}
#endif
#ifdef AIM
cerr << "\n\n time: " << (clock() - start) / 1.0 / CLOCKS_PER_SEC << "\n\n";
#endif
return 0;
}
//BE CAREFUL: IS INT REALLY INT?
template<typename T>
T binpow(T q, T w, T mod) {
if (!w)
return 1 % mod;
if (w & 1)
return q * 1LL * binpow(q, w - 1, mod) % mod;
return binpow(q * 1LL * q % mod, w / 2, mod);
}
template<typename T>
T gcd(T q, T w) {
while (w) {
q %= w;
swap(q, w);
}
return q;
}
template<typename T>
T lcm(T q, T w) {
return q / gcd(q, w) * w;
}
template <typename T>
void make_unique(vector<T>& vec) {
sort(all(vec));
vec.erase(unique(all(vec)), vec.end());
}
template<typename T>
void relax_min(T& cur, T val) {
cur = min(cur, val);
}
template<typename T>
void relax_max(T& cur, T val) {
cur = max(cur, val);
}
mt19937 rng((unsigned long long)chrono::steady_clock::now().time_since_epoch().count());
void precalc() {
}
#define int li
const li mod = 1000000007;
//const int mod = 998244353;
//using ull = unsigned long long;
void add(int& cur, int val) {
cur += val;
cur %= mod;
}
void solve(__attribute__((unused)) bool read) {
int n;
vector<int> c;
vector<int> b;
cin >> n;
c.resize(n);
for (int& x : c) {
cin >> x;
}
b.resize(n - 1);
for (int& x : b) {
cin >> x;
}
vector<int> b_pref_sum(n, 0);
vector<int> cached_b_sum(n, 0);
for (int k = 1; k < n; ++k) {
b_pref_sum[k] = b_pref_sum[k - 1] + b[k - 1];
cached_b_sum[k] = cached_b_sum[k - 1] + b_pref_sum[k];
}
int Q;
cin >> Q;
while (Q--) {
int x;
cin >> x;
if (x > c[0]) {
cout << "0\n";
continue;
}
vector<vector<int>> sum_dp(n + 1, vector<int>(n * 100 + 1, 0));
sum_dp[0][0] = 1;
for (int i = 0; i < n; ++i) {
for (int s = 0; s < sum_dp[i].size(); ++s) {
if (sum_dp[i][s] == 0) {
continue;
}
for (int take = 0; take <= c[i]; ++take) {
if (s + take >= x * (i + 1) + cached_b_sum[i]) {
add(sum_dp[i + 1][s + take], sum_dp[i][s]);
}
}
}
}
int res = 0;
for (auto& val : sum_dp[n]) {
add(res, val);
}
cout << res << "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef pair<int, int> pi;
int n;
const int maxn = 105;
int c[maxn], b[maxn];
ll pb[maxn], ppb[maxn];
ll dp[maxn][maxn * maxn];
ll pre[maxn][maxn * maxn];
ll S;
const int mod = 1e9 + 7;
void add(ll &a, ll b){
a += b;
if(a >= mod)
a -= mod;
}
ll get(ll x){
dp[0][0] = 1;
for(int i = 0;i < n;i++){
for(int j = 0;j <= S;j++){
pre[i][j] = dp[i][j];
if(j > 0)
add(pre[i][j], pre[i][j-1]);
}
ll lb = x * (i + 1) + ppb[i];
for(ll j = max(0LL, lb);j <= S;j++){
ll l = max(x * i + ((i > 0) ? ppb[i-1] : 0), 1LL * j - c[i+1]);
ll tmp;
if(l <= j)
tmp = (pre[i][j] - ((l > 0) ? pre[i][l-1] : 0) + mod) % mod;
else
tmp = 0;
add(dp[i+1][j], tmp);
}
}
ll ans = 0;
for(int j = 0;j <= S;j++){
add(ans, dp[n][j]);
}
return ans;
}
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
S = 0;
c[0] = 0;
for(int i = 1;i <= n;i++){
cin >> c[i];
S += c[i];
}
b[0] = 0;
pb[0] = 0;
ppb[0] = 0;
for(int i = 1;i < n;i++){
cin >> b[i];
pb[i] = pb[i-1] + b[i];
ppb[i] = ppb[i-1] + pb[i];
}
int Q;
cin >> Q;
ll x;
cin >> x;
cout << get(x) << endl;
return 0;
}
|
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
#define mod 1000000007
using namespace std;
int n,m;
int c[109],b[109];
int smb[109],ssb[109];
int f[109][10009],sf[109][10009],g[10009];
int pt[109],smc[109];
pii q[100009];
int ans[100009];
int mo(int x)
{
f[0][0]=1;
for(int i=1;i<=n;i++)
{
int mn=i*x+ssb[i-1],lp=0,sm=0;
for(int j=0;j<=smc[i];j++)
{
(sm+=f[i-1][j])%=mod;
(lp<j-c[i])&&((sm+=mod-f[i-1][lp])%=mod);
lp+=(lp<j-c[i]);
// printf("i:%d j:%d lp:%d sm:%d\n",i,j,lp,sm);
f[i][j]=j>=mn?sm:0;
}
}
int ans=0;
for(int i=0;i<=smc[n];i++)
ans=(ans+f[n][i])%mod;
return ans;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",c+i);
smc[i]=smc[i-1]+c[i];
}
for(int i=1;i<=n-1;i++)
{
scanf("%d",b+i);
smb[i]=smb[i-1]+b[i];
ssb[i]=ssb[i-1]+smb[i];
}
scanf("%d",&m);
for(int i=1;i<=m;i++)
{
scanf("%d",&q[i].fi);
q[i].se=i;
}
sort(q+1,q+m+1);
for(int k=1;k<=1000;k++)
for(int i=1;i<=m;i++)
ans[q[i].se]=mo(q[i].fi);
for(int i=1;i<=m;i++)
printf("%d\n",ans[i]);
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int c[110],b[110],sumb[110],sumc[110],f[110][11000];
signed main() {
int n,x;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",c+i);
for(int i=1;i<n;i++)
scanf("%d",b+i);
for(int i=1;i<=n;i++)
sumc[i]=sumc[i-1]+c[i];
for(int i=2;i<=n;i++)
sumb[i]=sumb[i-1]+b[i-1];
for(int i=1;i<=n;i++)
sumb[i]+=sumb[i-1];
scanf("%*d%d",&x);
for(int i=0;i<=c[1];i++)
f[0][i]=1;
sumc[n+1]=sumc[n];
for(int i=1;i<=n;i++) {
for(int j=max(i*x+sumb[i],0);j<=sumc[i];j++)
f[i][j]=(f[i-1][j]-(j-c[i]-1>=0?f[i-1][j-c[i]-1]:0)+mod)%mod;
for(int j=1;j<=sumc[i+1];j++)
f[i][j]=(f[i][j]+f[i][j-1])%mod;
}
printf("%d\n",f[n][sumc[n+1]]);
return 0;
}
|
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <array>
#include <random>
#include <chrono>
#include <string>
#include <queue>
#include <cassert>
#define int long long
#define pb push_back
#define pp pair<int,int>
#define ff first
#define dd second
#define mp make_pair
using namespace std;
int n, k, q, x, ans = 0;
int c[101];
int b[101];
int bsum[102];
const int maxSum = 100 * 100 + 2;
int mod = 1e9 + 7;
int dp[101][maxSum];
int psum[maxSum];
int getSum(int i) {
return bsum[i+1];
}
void solve() {
cin >> n;
for (int i = 0; i < n; ++i) cin >> c[i];
bsum[0] = 0;
for (int i = 0; i < n-1; ++i) {
cin >> b[i];
bsum[i+1] = bsum[i] + b[i];
}
cin >> q;
while (q--) {
cin >> x;
ans = 0;
psum[0] = 0;
for (int i = 0; i <= maxSum; ++i) {
dp[0][i] = (int)(i >= x && i <= c[0]);
psum[i+1] = psum[i] + dp[0][i];
}
int bb = 0;
for (int i = 1; i < n; ++i) {
bb += getSum(i-1);
for (int sum = 0; sum < 100*n+1; ++sum) {
dp[i][sum] = 0;
if ((sum - bb) >= x*(i + 1)) {
dp[i][sum] += (psum[sum+1] - psum[max(sum-c[i], 0ll)] + mod) % mod; // dp[i-1][sum] + ... + dp[i-1][sum-c[i]];
dp[i][sum] %= mod;
if (i == n-1) {
ans += dp[i][sum];
ans %= mod;
}
}
//cout << "i sum dp[i][sum] " << i << " " << sum << " " << dp[i][sum] << endl;
}
for (int sum = 0; sum <= maxSum; ++sum) {
psum[sum+1] = psum[sum] + dp[i][sum];
psum[sum+1] %= mod;
}
}
cout << ans << endl;
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
int z = 1;//; cin >> z;
while (z--) {
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int inf = 1e9;
const ll inf64 = 1e18;
const int mod = inf + 7;
inline int _mul(int a, int b) {
return (1ll * a * b) % mod;
}
inline void _add(int& x, int y) {
if ((x += y) >= mod)
x -= mod;
}
inline void _dec(int& x, int y) {
if ((x -= y) < 0)
x += mod;
}
const int MAXX = 105;
const int MAXS = 4e6;
vector<int> fast(int n, vector<int> c, vector<int> b, int q, vector<int> xs) {
vector<int> prB(n);
for (int i = 1; i < n; i++)
prB[i] = prB[i - 1] + b[i];
vector<int> B(n + 1);
for (int i = 2; i <= n; i++)
B[i] = B[i - 1] + prB[i - 1];
vector<int> cur(MAXS);
cur[0] = 1;
for (int i = 0; i < n; i++) {
vector<int> pu(MAXS);
for (int value = 0; value < MAXS; value++) {
// value + a[i] - x - prB[i] >= 0
// a[i] >= x + prB[i] - value
// 0 <= a[i] <= c[i + 1]
int le = max(0, xs[0] + prB[i] - value);
int ri = c[i + 1];
int base_value = value - xs[0] - prB[i];
le += base_value;
ri += base_value;
// for (int next_value = le; next_value <= ri; next_value++)
// _add(dp[i + 1][next_value], dp[i][value]);
if (le <= ri) {
if (le < MAXS)
_add(pu[le], cur[value]);
if (ri + 1 < MAXS)
_dec(pu[ri + 1], cur[value]);
}
// for (int ai = le; ai <= ri; ai++) {
// int next_value = base_value + ai;
// _add(dp[i + 1][next_value], dp[i][value]);
// }
}
for (int x = 0; x < MAXS; x++)
_add(pu[x + 1], pu[x]);
cur = pu;
}
int res = 0;
for (int value = 0; value < MAXS; value++)
_add(res, cur[value]);
return {res};
}
void work() {
int n;
cin >> n;
vector<int> c(n + 1);
for (int i = 1; i <= n; i++)
cin >> c[i];
vector<int> b(n);
for (int i = 1; i < n; i++)
cin >> b[i];
int q;
cin >> q;
vector<int> xs(q);
for (auto& x : xs)
cin >> x;
vector<int> res = fast(n, c, b, q, xs);
for (auto x : res)
cout << x << "\n";
}
int main() {
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
work();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<int, int> pi;
int n;
const int maxn = 105;
int c[maxn], b[maxn];
ll dp[maxn][maxn * maxn];
const int mod = 1e9 + 7;
void add(ll &a, ll b){
a += b;
if(a >= mod)
a -= mod;
}
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
ll S = 0;
c[0] = 0;
for(int i = 1;i <= n;i++){
cin >> c[i];
S += c[i];
}
b[0] = 0;
for(int i = 1;i < n;i++){
cin >> b[i];
}
dp[0][0] = 1;
int Q;
cin >> Q;
ll x;
cin >> x;
ll B = 0;
ll B2 = 0;
for(int i = 0;i < n;i++){
B += b[i];
B2 += B;
for(int j = 0;j <= S;j++){
ll sum = x * (i + 1) + B2;
ll lb = max(0LL, sum - j);
for(int k = lb;k <= c[i+1] and k + j <= S;k++){
add(dp[i+1][k + j], dp[i][j]);
}
}
}
ll ans = 0;
for(int j = 0;j <= S;j++){
add(ans, dp[n][j]);
}
cout << ans << endl;
return 0;
}
|
#include<bits/stdc++.h>
#define ll long long
#define sz(x) ((int)x.size())
#define fi first
#define se second
#define pii pair<int,int>
#define pk push_back
const int maxn=1e2+5;
const int mo=1e9+7;
const int Max=1e5;
const int maxm=2e5+5;
using namespace std;
int rd(){
int x=0,f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c))x=(x<<3)+(x<<1)+c-'0',c=getchar();
return x*f;
}
int n,b[maxn],c[maxn],q,lim=1,L,R,m,ans[maxm],all;
int f[maxm],g[maxm];
int sum_b[maxn];
int pls(int x,int y){return x+y>=mo?x+y-mo:x+y;}
int dec(int x,int y){return x-y<0?x-y+mo:x-y;}
int solve(int x){
int res=0;
for(int i=1;i<=all;i++)f[i]=0;f[0]=1;
for(int i=1;i<=n;i++){
for(int j=0;j<=all;j++)g[j]=pls(f[j],(j?g[j-1]:0)),f[j]=0;
for(int j=max(0,sum_b[i]+x*i);j<=all;j++)f[j]=dec(g[j],(j>c[i]?g[j-c[i]-1]:0));
}
for(int i=0;i<=all;i++)res=pls(res,f[i]);
return res;
}
int main(){
n=rd();
for(int i=1;i<=n;i++)c[i]=rd(),lim=1LL*lim*(c[i]+1)%mo,m=max(m,c[i]),all+=c[i];
for(int i=1;i<n;i++)b[i]=rd();
q=rd();
for(int i=1;i<=n;i++)for(int j=1;j<i;j++)sum_b[i]+=(i-j)*b[j];
L=0,R=Max;
for(int i=1;i<=n;i++)L=min(L,-((sum_b[i]-1)/i+1)),R=min(R,(n*m-sum_b[i]-1)/i+1);L=max(L,-Max);
for(int i=L;i<=R;i++)ans[i+Max]=solve(i);
for(int x;q;q--){
x=rd();
if(x<L)printf("%d\n",lim);
else if(x>R)puts("0");
else printf("%d\n",ans[x+Max]);
}
return 0;
}
|
// #pragma comment(linker, "/stack:200000000000")
#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using i128 = __int128_t;
using u128 = __uint128_t;
using u64 = uint64_t;
//define
#define int long long
#define ll int
#define trav(i,v) for(auto i: v)
#define rep(i,n) for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define itn int
#define sz(x) (int)x.size()
//typedef
typedef unsigned long long ull;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< std::vector<int> > vvi;
typedef std::vector< std::pair < pii, int > > vpp;
const long long MOD = 1000000007;
// const long long MOD = 998244353;
const long double PI = 3.141592653589793238;
const long long pi = 31415926;
const long long inf = 1000000000000000000;
const long long small_inf = INT_MAX;
const int N = 200;
int modpow(int x, int n = MOD-2, int mod = MOD){ int res=1; while(n>0){ if(n&1) res=res*x%mod; x=x*x%MOD; n>>=1;} return res;}
int power(int x, int n){ int res=1; while(n>0){ if(n&1) res=res*x; x=x*x; n>>=1; } return res;}
int add(int x, int y){ return (x+y)%MOD; }
int mult(int x, int y){ return (x*y)%MOD; }
void init(){
}
void solve()
{
/*Don't hurry, nothing good comes if you rush*/
int n;
cin>>n;
vi c(n+1,0);
vi b(n+1,0);
repu(i,1,n){
cin>>c[i];
}
repu(i,1,n-1){
cin>>b[i];
}
int q;
cin>>q;
int y;
vi sum(n+1,0);
vi v(n+1,0);
cin>>y;
v[1] = y;
repu(i,2,n){
v[i] = v[i-1]+b[i-1];
}
repu(i,1,n){
sum[i] = sum[i-1]+v[i];
}
vvi dp(n+1,vi(10001,0));
repu(i,max(0ll, sum[1]),c[1]){
dp[1][i] = 1;
}
repu(i,2,n){
repu(x,0,c[i]){
repd(j,10000,max(x,sum[i])){
dp[i][j] += dp[i-1][j-x];
dp[i][j] %= MOD;
}
}
}
int ans = 0;
repd(i,10000,max(0ll, sum[n])){
ans += dp[n][i];
ans %= MOD;
}
cout<<ans<<endl;
}
void clear_global(){
}
signed main(){
// #ifndef ONLINE_JUDGE
// freopen("./input.txt", "r", stdin);
// freopen("./output.txt", "w", stdout);
// #endif
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int t23 = 1, tt23 = 1;
// cin>>t23;
init();
while(tt23<=t23)
{
// cout<<"Case #"<<tt23<<": ";
solve();
tt23++;
clear_global();
}
cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}
|
#include<bits/stdc++.h>
using namespace std;
const int N = 105;
const int mod = 1e9+7;
int n,c[N],b[N],q,f[N][N*N],ans;
int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&c[i]);
for(int i=1;i<n;i++) scanf("%d",&b[i]);
for(int i=1;i<n;i++) b[i] += b[i-1];
for(int i=1;i<n;i++) b[i] += b[i-1];
scanf("%d",&q);scanf("%d",&q);
f[0][0] = 1;
for(int i=1;i<=n;i++)
for(int j=i*q+b[i-1];j<N*N;j++)
for(int k=0;k<=c[i]&&k<=j;k++)
f[i][j] = (f[i][j]+f[i-1][j-k])%mod;
for(int i=0;i<N*N;i++) ans = (ans+f[n][i])%mod;
printf("%d\n",ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define RANGE(x) x.begin(),x.end()
void one(){
}
int main(){
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
vector<int> b(n-1);
vector<int> c(n);
ll allways= 1;
for(int i=0;i<n;++i){
cin>>c[i];
allways*=c[i];
allways%=mod;
}
for(int i=1;i<n;++i){
cin>>b[i-1];
}
int Q;
cin>>Q;
vector<int> bbars(n);
vector<int> bpre(n);
bpre[0]=0;
bbars[0]=0;
for(int i=1;i<n;++i){
bpre[i]=bpre[i-1]+b[i-1];
bbars[i]=bbars[i-1]+bpre[i];
}
while(Q-->0){
int x;
cin>>x;
ll offset = 0;
ll failures = 0;
vector<ll> curr(1,1);
for(int k=0; k<n;++k){
int os = curr.size();
vector<ll> temp(os+c[k]);
ll val = 0;
for(int i=0;i<temp.size();++i){
if(i>=c[k]+1)val-=curr[i-c[k]-1];
if(i<os)val+=curr[i];
temp[i] = val%mod;
}
// check if i>0;
int min =bbars[k] + (k+1)*x;
if(offset<min){
curr.clear();
if(min-offset<temp.size()){
curr.insert(curr.end(),temp.begin() + min-offset,temp.end());
offset = min;
}
}
else{
swap(temp,curr);
}
}
ll res = 0;
for(ll i:curr){
res+=i;
}
cout<<res%mod<<endl;
}
cout<<flush;
}
|
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxl=105,maxs=10005,mod=1e9+7;
int read(){
int s=0,w=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') w=-w;ch=getchar();}
while (ch>='0'&&ch<='9'){s=(s<<1)+(s<<3)+(ch^'0');ch=getchar();}
return s*w;
}
int n,l,r,L,ans;
int c[maxl],b[maxl],pre[maxl],f[maxl][maxs];
void chksum(int x,int &y){y=(x+y)%mod;}
signed main(){
n=read();
for (int i=1;i<=n;i++) c[i]=read();
for (int i=1;i<=n;i++) b[i]=read(),pre[i]=pre[i-1]+b[i];
L=read();
f[0][0]=1;
for (int i=1;i<=n;i++){
l+=(L+pre[i-1]),r+=c[i];
for (int j=max(l,0ll);j<=r;j++){
for (int k=0;k<=min(j,c[i]);k++) chksum(f[i-1][j-k],f[i][j]);
}
}
for (int i=0;i<=r;i++) chksum(f[n][i],ans);
cout<<ans<<endl;
return 0;
}
|
#include<iostream>
#include<cstdio>
using namespace std;
const int N=105;
const int MOD=1000000007;
int n,q;
int c[N];
int b[N];
long long sb[N];
int f[N][N*N];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&c[i]);
for(int i=1;i<n;i++)
scanf("%d",&b[i]);
for(int i=1;i<n;i++)
sb[i]=sb[i-1]+b[i];
for(int i=1;i<n;i++)
sb[i]+=sb[i-1];
scanf("%d",&q);
while(q--)
{
int x;
scanf("%d",&x);
f[0][0]=1;
for(int i=1;i<=n;i++)
for(int j=0;j<=100*(i);j++)
if(f[i-1][j])
for(int k=0;k<=c[i];k++)
if(j+k>=i*x+sb[i-1]) f[i][j+k]=(f[i][j+k]+f[i-1][j])%MOD;
int ans=0;
for(int j=0;j<=100*n;j++)
ans=(ans+f[n][j])%MOD;
printf("%d\n",ans);
}
return 0;
}
|
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cassert>
#include <map>
#include <numeric>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <cmath>
#include <iomanip>
#include <iterator>
#include <bitset>
#include <unordered_map>
#include <complex>
#include <unordered_set>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
clock_t timeStart, timeFinish;
void timeBegin() {
timeStart = clock();
}
void timeEnd() {
timeFinish = clock();
}
void timeDuration() {
timeEnd();
double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC);
cout << "Time taken by program is : " << fixed << time_taken << setprecision(5);
cout << " sec " << endl;
}
class InputReader {
public:
InputReader() {
input_file = stdin;
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
InputReader(const char *file_name) {
input_file = fopen(file_name, "r");
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
inline InputReader &operator>>(int &n) {
while ((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') {
advance();
}
int sign = 1;
if (buffer[cursor] == '-') {
sign = -1;
advance();
}
n = 0;
while ('0' <= buffer[cursor] && buffer[cursor] <= '9') {
n = n * 10 + buffer[cursor] - '0';
advance();
}
n *= sign;
return *this;
}
private:
FILE *input_file;
static const int SIZE = 1 << 17;
int cursor;
char buffer[SIZE];
inline void advance() {
++cursor;
if (cursor == SIZE) {
cursor = 0;
fread(buffer, SIZE, 1, input_file);
}
}
};
const int MAXN = 100;
const int MAXVAL = 100;
const int MOD = 1000000007;
int c[1 + MAXN], b[1 + MAXN];
int dp[1 + MAXN][1 + MAXN * MAXVAL];
int sum[1 + MAXN][1 + MAXN * MAXVAL];
void sub(int &x, int y) {
x -= y;
if (x < 0) {
x += MOD;
}
}
void add(int &x, int y) {
x += y;
if (x >= MOD) {
x -= MOD;
}
}
int compute(int n, int s, int x) {
memset(dp, 0, sizeof(dp));
memset(sum, 0, sizeof(sum));
dp[0][0] = 1;
for (int j = 0; j <= s; j++) {
sum[0][j] = 1;
}
for (int i = 1; i <= n; i++) {
for (int j = max(0, i * x + b[i]); j <= s; j++) {
dp[i][j] = sum[i - 1][j];
if (j > c[i]) {
sub(dp[i][j], sum[i - 1][j - c[i] - 1]);
}
sum[i][j] = dp[i][j];
if (j > 0) {
add(sum[i][j], sum[i][j - 1]);
}
}
}
return sum[n][s];
}
int main() {
timeBegin();
//ifstream cin("input.in");
//ofstream cout("output.out");
ios_base::sync_with_stdio(false);
cin.tie(0);
srand(time(0));
int n, s = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> c[i];
s += c[i];
}
for (int i = 2, bSum = 0; i <= n; i++) {
cin >> b[i];
bSum += b[i];
b[i] = b[i - 1] + bSum;
}
int q;
cin >> q;
for (int i = 1; i <= q; i++) {
int x;
cin >> x;
cout << compute(n, s, x) << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define debug(a) cerr << #a << ": " << (a) << '\n';
#define debug_arr(a, n) { cerr << #a << " "; rep(i, 0, n) cerr << a[i] << " \n"[(i + 1) == n]; }
#define debug_two(a, b) cerr << #a << ": " << (a) << ", " << #b << ": " << (b) << '\n';
template <typename num_t>
inline void add_mod(num_t& a, const long long& b, const int& m) { a = (a + b) % m; if (a < 0) a += m; }
template <typename num_t>
inline bool update_max(num_t& a, const num_t& b) { return a < b ? a = b, true : false; }
template <typename num_t>
inline bool update_min(num_t& a, const num_t& b) { return a > b ? a = b, true : false; }
template <typename num_t>
num_t gcd(num_t lhs, num_t rhs) { return !lhs ? rhs : gcd(rhs % lhs, lhs); }
template <typename num_t>
num_t pw(num_t n, num_t k, num_t mod) {
num_t res = 1; for (; k > 0; k >>= 1) { if (k & 1) res = 1ll * res * n % mod; n = 1ll * n * n % mod; } return res;
}
int invserse(int n, int mod) {
return pw(n, mod - 2, mod);
}
typedef long long int64;
const int mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
vector<int> c(n); rep(i, 0, n) cin >> c[i];
vector<int> b(n, 0);
rep(i, 1, n) {
cin >> b[i];
b[i] += b[i - 1];
}
vector<int> sum_b(n, 0);
rep(i, 0, n) {
sum_b[i] = b[i];
if (i) sum_b[i] += sum_b[i - 1];
}
const int base = 10000;
int q = 0; cin >> q;
while (q-- > 0) {
int x; cin >> x;
if (x > c[0]) {
cout << 0; return;
}
vector<int> pre, cur;
cur.assign(base * 2 + 1, 0);
rep(val, max(0, x), c[0] + 1) {
cur[val + base] = 1;
}
rep(i, 1, sz(cur)) cur[i] += cur[i - 1];
rep(i, 1, n) {
pre = cur;
fill_n(cur.begin(), sz(cur), 0);
rep(sum, 0, sz(cur)) if (sum - base - sum_b[i] >= (i + 1) * x) {
cur[sum] = pre[sum];
if (sum - c[i] - 1 >= 0) {
add_mod(cur[sum], -pre[sum - c[i] - 1], mod);
}
}
rep(sum, 1, sz(cur)) add_mod(cur[sum], cur[sum - 1], mod);
}
cout << cur.back() << '\n';
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL_
freopen("in.txt", "r", stdin);
#endif
const bool multiple_test = false;
int test = 1;
if (multiple_test)
cin >> test;
for(int i = 0; i < test; ++i) {
//printf("Case #%d: ", i + 1);
solve();
}
#ifdef _LOCAL_
cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
#endif
}
|
#include <bits/stdc++.h>
using namespace std;
const int md=1000000007,MID=111*111;
int n,q,x,i,ii,i1,j,lst,len,lensum,cur,r,b[111],c[111];
long long f[2][MID];
map<int,int> was;
int main() {
scanf("%d",&n);
for (i=1; i<=n; i++) scanf("%d",&c[i]);
for (i=1; i<n; i++) scanf("%d",&b[i]);
scanf("%d",&q);
while (q--) {
scanf("%d",&x);
if (x>c[1]) { puts("0"); continue; }
//x=max(x,-102);
auto it=was.find(x);
if (it!=was.end()) { printf("%d\n",it->second); continue; }
r=cur=len=lensum=0;
memset(f,0,sizeof(f));
f[0][0]=1;
for (i=1; i<=n; i++) {
ii=i&1; i1=1-ii;
cur+=c[i];
for (j=0; j<=cur; j++) for (f[ii][j]=lst=0; lst<=j && lst<=c[i]; lst++) if (f[i1][j-lst]) {
if (x*i+lensum<=j) f[ii][j]=(f[ii][j]+f[i1][j-lst])%md;
}
len+=b[i];
lensum+=len;
}
for (j=0; j<=cur; j++) r=(r+f[n&1][j])%md;
printf("%d\n",r);
was[x]=r;
}
return 0;
}
|
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int MOD = 1e9+7;
ll dp[101][10010];
int a[101], b[101];
int main(){
int n;
scanf("%d", &n);
for (int i=0;i<n;i++){
scanf("%d", a+i);
}
for (int i=0;i<n-1;i++){
scanf("%d", b+i);
}
int q, x;
scanf("%d %d", &q, &x);
ll S = x;
for (int j=max(x, 0);j<=a[0];j++) dp[0][j] = 1;
for (int i=1;i<n;i++){
x += b[i-1];
S += x;
for (int j=max(S, 0LL);j<10010;j++){
for (int k=0;k<=a[i];k++){
if (j-k<0) break;
dp[i][j] += dp[i-1][j-k];
if (dp[i][j]>=MOD) dp[i][j] -= MOD;
}
}
}
ll ans = 0;
for (int j=0;j<10010;j++){
ans += dp[n-1][j];
if (ans>=MOD) ans -= MOD;
}
printf("%lld\n", ans);
return 0;
}
|
#ifndef __APPLE__
#include <bits/stdc++.h>
#else
#include <iostream>
#include <cstring>
#include <algorithm>
#endif
using namespace std;
typedef long long ll;
const int N = 105;
const int M = 1e9 + 7;
int n, c[N], b[N], q, x, bp[N], bpp[N];
ll dp[N][N * N], sdp[N][N * N], cp[N];
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> c[i];
cp[i] = cp[i - 1] + c[i];
}
for (int i = 1; i <= n - 1; i++)
{
cin >> b[i];
bp[i] = bp[i - 1] + b[i];
bpp[i] = bpp[i - 1] + bp[i];
}
cin >> q;
while (q--)
{
cin >> x;
memset(dp, 0, sizeof(dp));
memset(sdp, 0, sizeof(sdp));
for (int i = 0; i < N; i++) sdp[0][i] = 1;
for (int i = 1; i <= n; i++)
{
int minj = max(0, i * x + bpp[i - 1]);
for (int j = minj; j <= cp[i]; j++)
{
sdp[i][j] = sdp[i][j] + sdp[i-1][min((int)cp[i-1], j)];
if (j > c[i])
sdp[i][j] = (sdp[i][j] - sdp[i-1][j-c[i]-1]+M) % M;
}
for (int j = 1; j <= cp[i]; j++) {
sdp[i][j] += sdp[i][j-1] + M;
sdp[i][j] %= M;
}
}
cout << sdp[n][cp[n]] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 105, mod = 1000000007;
int n, m, x, b[N], c[N], l, r, ans, f[N][N * N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
for (int i = 1; i < n; i++) scanf("%d", &b[i]);
scanf("%d%d", &m, &x), f[0][0] = 1;
for (int i = 1; i <= n; i++) {
l = i * x, r += c[i];
for (int j = 1; j <= i; j++) l += b[j] * (i - j);
for (int j = r; j >= max(l, 0); j--) {
for (int k = 0; k <= min(c[i], j); k++) {
f[i][j] = (f[i][j] + f[i - 1][j - k]) % mod;
}
}
} for (int i = 0; i <= r; i++) (ans += f[n][i]) %= mod;
printf("%d\n",ans);
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
/* SOLVE NOTES
(S + a) / n >= (T - b) / m
then
S / n < T / m
we have
S / n - T / m >= - a / n - b / m
S / n - T / m < 0
3 -3
1 5 -5 2 => 1 0 0 2
1/2 1/2 0 2
1/2 1/4 1/4 2
1/3 1/3 1/3 2
A x y
P: A A+x A+x+y
[x > y]
A x+y/2 x+y/2
P: A A+(x+y)/2 A+x+y
YOU TAKE THE LOWER HULL!
*/
int main() {
int n; scanf("%d", &n);
vector<int> c(n), b(n-1);
for (int i = 0; i < n; ++i) scanf("%d", &c[i]);
for (int i = 0; i < n - 1; ++i) scanf("%d", &b[i]);
vector<int> bDeduction(n);
for (int i = 0; i < n - 1; ++i) bDeduction[i + 1] = bDeduction[i] + b[i];
for (int i = 0; i < n - 1; ++i) bDeduction[i + 1] += bDeduction[i];
int q; scanf("%d", &q);
ll maxSum = accumulate(begin(c), end(c), 0LL);
while (q--) {
int x; scanf("%d", &x);
// count the number of ways to be at i, with a partial sum of P,
// without going below the (0, 0) - (1, x) line
// consider a[0], a[1] - b[0], a[2] - b[0] - b[1], ...
// so we only have to average points
// then consider the partial sums of these
// so 0, a[0], a[0] + a[1] - b[0], ...
// so an average becomes a take-the-midpoint
// but this ONLY works if you're bumping down a concave section
// maxsum here is without bDeduction
// x y z
// 0, x, x + y - 2, x + y + z - 5
// 0 1 4
// 0 -1 1
// 0 0 -1 0
// 0 -1/2 -1 0
// 0 -1/2 -1/2 1
vector<vector<ll>> waysToBeAt(n + 1, vector<ll>(maxSum + 1));
waysToBeAt[0][0] = 1;
for (int elem = 1; elem <= n; ++elem) {
for (int s = 0; s <= maxSum; ++s) {
int actualYC = s - bDeduction[elem-1];
if (actualYC < x * elem) continue;
for (int vTaken = 0; vTaken <= c[elem-1]; ++vTaken) {
if (s - vTaken < 0) continue;
waysToBeAt[elem][s] = (waysToBeAt[elem][s] +
waysToBeAt[elem-1][s-vTaken]) % MOD;
}
}
}
printf("%lld\n", accumulate(begin(waysToBeAt[n]), end(waysToBeAt[n]), 0LL) % MOD);
}
}
|
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
#define INF 2001001001
#define MOD 1000000007
ll N,X,C[105],B[105],D[105],D1[105];
int Q;
ll dp[105][10005];
ll C2[105];
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>N;
for (int i=1;i<=N;i++)
cin>>C[i];
for (int i=1;i<N;i++)
cin>>B[i];
cin>>Q;
cin>>X;
D1[1]=X;
for (int i=2;i<=N;i++)
D1[i]=D1[i-1]+B[i-1];
for (int i=1;i<=N;i++){
D[i]=D[i-1]+D1[i];
C2[i]=C2[i-1]+C[i];
}
dp[0][0]=1;
for (int i=0;i<N;i++){ //adding in element i+1
for (int j=0;j<=C2[i];j++){
if (dp[i][j]==0) continue;
for (int k=0;k<=C[i+1];k++){
if (j+k>=D[i+1]){
dp[i+1][j+k]+=dp[i][j];
if (dp[i+1][j+k]>=MOD)
dp[i+1][j+k]%=MOD;
}
}
}
}
ll ans=0;
for (int i=0;i<=10000;i++)
ans=(ans+dp[N][i])%MOD;
cout<<ans<<endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int BASE = 1e9 + 7;
int n, c[111], b[111], q, x[100100], sumB[111];
long long f[111][10100];
int main()
{
cin >> n;
for (int i = 0; i < n; i++)
cin >> c[i];
for (int i = 0; i < n - 1; i++)
{
cin >> b[i];
if (i)
b[i] += b[i - 1];
sumB[i] = b[i];
if (i)
sumB[i] += sumB[i - 1];
}
cin >> q;
for (int i = 0; i < q; i++)
cin >> x[i];
for (int i = max(0, x[0]); i <= c[0]; i++)
f[0][i] = 1;
for (int i = 1; i < n; i++)
for (int sum = 0 ; sum <= i * 100; sum++)
if (f[i - 1][sum])
for (int j = 0; j <= c[i]; j++)
{
int newSum = sum + j;
if (newSum >= x[0] * (i + 1) + sumB[i - 1])
f[i][newSum] = (f[i][newSum] + f[i - 1][sum]) % BASE;
}
long long ans = 0;
for (int i = 0; i <= n * 100; i++)
ans = (ans + f[n - 1][i]) % BASE;
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 105;
const int MOD = 1000000007;
int n;
int suff[N];
int dp[N][N * N];
int pref[N][N * N];
int val[N], c[N], b[N];
int cnt = 0;
int x[N];
void backtrack(int k) {
for (int i = 0; i <= c[k]; i++) {
x[k] = i;
if (k == n) {
int sum = 0;
bool ok = 1;
for (int i = 1; i <= n; i++) {
sum += x[i];
if (sum < val[i]) ok = 0;
}
cnt += ok;
} else backtrack(k + 1);
}
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> c[i];
for (int i = 1; i < n; i++) cin >> b[i];
int q, x;
cin >> q >> x;
int cur = x;
for (int i = 1; i <= n; i++) {
val[i] = val[i - 1] + cur;
cur += b[i];
// cout << val[i] << '\n';
}
// backtrack(1);
suff[n + 1] = 1;
for (int i = n; i >= 1; i--) suff[i] = suff[i + 1] * (c[i] + 1) % MOD;
dp[0][0] = 1;
for (int j = 0; j < N*N; j++) pref[0][j] = 1;
int res = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < N * N; j++) {
int l = max<int>(0, j - c[i]);
int r = j;
dp[i][j] = pref[i - 1][r] - (l > 0 ? pref[i - 1][l - 1] : 0);
dp[i][j] = (dp[i][j] + MOD) % MOD;
}
// for (int j = 0; j < 10; j++) cout << dp[i][j] << ' ';
// cout << endl;
for (int j = 0; j < min(N * N, val[i]); j++) {
res = (res + dp[i][j] * suff[i + 1]) % MOD;
dp[i][j] = 0;
}
pref[i][0] = dp[i][0];
for (int j = 1; j < N * N; j++) pref[i][j] = (dp[i][j] + pref[i][j - 1]) % MOD;
}
// cout << res << endl;
res = (suff[1] - res + MOD) % MOD;
cout << res << '\n';
return 0;
}
|
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
inline int read()
{
int f = 1, x = 0;
char ch;
do{
ch = getchar();
if (ch == '-')
f = -1;
}while(ch < '0' || ch > '9');
do{
x = x * 10 + ch - '0';
ch = getchar();
}while(ch >= '0' && ch <= '9');
return f * x;
}
const int N = 100;
const int M = 2e5;
const int mod = 1e9 + 7;
int n, q;
int b[N + 1], c[N + 1], sumc[N + 1];
int f[N + 1][N * N + 1], g[N * N + 1], ans[M + 1];
int sum = 1, l = M / 2, r = M / 2;
inline int dp(int x)
{
memset(f, 0, sizeof(int) * (N + 1));
f[0][0] = 1;
for (int i = 0; i <= N * N; i++)
g[i] = 1;
for (int i = 1; i <= n; i++) {
for (int j = sumc[i]; j >= 0; j--)
f[i][j] = (g[j] - ((j - c[i] > 0)?g[j - c[i] - 1]:0) + mod) % mod;
for (int j = 0; j < x * i + b[i - 1]; j++)
f[i][j] = 0;
g[0] = f[i][0];
for (int j = 1; j <= N * N; j++)
g[j] = (g[j - 1] + f[i][j]) % mod;
}
return g[sumc[n]];
}
int main()
{
n = read();
for (int i = 1; i <= n; i++) {
c[i] = read();
sumc[i] = sumc[i - 1] + c[i];
sum = 1ll * sum * (c[i] + 1) % mod;
}
for (int i = 1; i < n; i++)
b[i] = b[i - 1] + read();
for (int i = 1; i < n; i++)
b[i] += b[i - 1];
q = read();
for (int i = 1; i <= n; i++) {
l = min(l, (int)ceil(-b[i - 1] / i));
r = min(r, (int)floor((sumc[i] - b[i - 1]) / i));
}
l = max(l, -M / 2);
for (int i = l; i <= r; i++)
ans[i + M / 2] = dp(i);
for (int i = 1; i <= q; i++) {
int x = read();
printf("%d\n", x < l?sum:(x > r?0:ans[x + M / 2]));
}
return 0;
}
|
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second
const int mod = 1000000007;
const int m = 101, mxk = m * m;
int n, k, q;
int a[m], b[m], f[m], dp[mxk];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
k = n * m;
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 2; i <= n; i++) cin >> b[i], b[i] += b[i - 1];
int s = 0x3f3f3f3f, e = 0x3f3f3f3f;
for(int i = 1, j = 0; i <= n; i++){
j += a[i], b[i] += b[i - 1];
s = min(s, -b[i] / i - 1);
e = min(e, (j - b[i]) / i + 1);
}
for(int i = s; i <= e; i++){
memset(dp, 0, sizeof(dp));
dp[0] = 1;
for(int j = 1; j <= n; j++){
for(int l = 1; l <= k; l++) (dp[l] += dp[l - 1]) %= mod;
for(int l = k; ~l; l--){
(dp[l] += mod - (l < i * j + b[j] ? dp[l] : l > a[j] ? dp[l - a[j] - 1] : 0)) %= mod;
}
}
for(int j = 0; j <= k; j++) (f[i - s] += dp[j]) %= mod;
}
cin >> q;
while(q--){
int x;
cin >> x;
x = max(s, min(e, x));
cout << f[x - s] << endl;
}
return 0;
}
|
#include<bits/stdc++.h>
using namespace std;
const int N=105,mod=1e9+7;
inline int add(int a,int b){return a+b>=mod?a+b-mod:a+b;}
inline int mul(int a,int b){return 1ll*a*b%mod;}
int n,m,l,r;
int b[N],c[N],p[N];
int f[N*N],g[N*N];
map<int,int> ans;
inline int solve(int x){
for(int i=0;i<=n*100;i++)g[i]=1;
for(int i=1;i<=n;i++){
for(int j=0;j<max(i*x+p[i],0);j++)f[j]=0;
for(int j=max(i*x+p[i],0);j<=n*100;j++){
if(j>c[i])f[j]=add(g[j],mod-g[j-c[i]-1]);
else f[j]=g[j];
}
g[0]=f[0];
for(int j=1;j<=n*100;j++)g[j]=add(g[j-1],f[j]);
}
return g[n*100];
}
int main(){
cin>>n;
for(int i=1;i<=n;i++)cin>>c[i];
for(int i=1;i<n;i++)cin>>b[i];
for(int i=1;i<=n;i++)
for(int j=1;j<i;j++)p[i]+=(i-j)*b[j];
l=0,r=100000;
for(int i=1;i<=n;i++)l=min(l,-((p[i]-1)/i+1)),r=min(r,(n*100-p[i]-1)/i+1);
for(int i=l;i<=r;i++)ans[i]=solve(i);
int q;
cin>>q;
int res=1;
for(int i=1;i<=n;i++)res=mul(res,c[i]+1);
while(q--){
int x;
scanf("%d",&x);
if(x<l)printf("%d\n",res);
else if(x>r)puts("0");
else printf("%d\n",ans[x]);
}
return 0;
}
|
#include <iostream>
#include <algorithm>
constexpr int N = 105;
constexpr int p = 1000000007;
int add(int x, int y) { return (x += y) >= p ? x - p : x; }
int sub(int x, int y) { return (x -= y) < 0 ? x + p : x; }
int n, q, k;
int c[N], b[N];
int f[N][N * N];
int s[2][N * N];
int l[N];
int main() {
std::ios::sync_with_stdio(false), std::cin.tie(nullptr);
std::cin >> n;
int sumc = 0;
for (int i = 1; i <= n; ++i) std::cin >> c[i], sumc += c[i];
for (int i = 1; i < n; ++i) std::cin >> b[i];
std::cin >> q;
while (q--) {
std::cin >> k;
int sumb = k;
for (int i = 1; i <= n; ++i) {
l[i] = l[i - 1] + sumb;
sumb += b[i];
}
f[0][0] = 1;
for (int i = 0; i <= sumc; ++i) s[0][i] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < l[i] && j <= sumc; ++j) s[1][j] = 0;
for (int j = std::max(l[i], 0); j <= sumc; ++j) {
f[i][j] = add(f[i][j], sub(s[0][j], j - c[i] - 1 >= 0 ? s[0][j - c[i] - 1] : 0));
s[1][j] = add(f[i][j], j > 0 ? s[1][j - 1] : 0);
}
std::swap(s[0], s[1]);
}
int min = k * n + sumb - k;
int ans = 0;
for (int i = std::max(min, 0); i <= sumc; ++i) {
ans = add(ans, f[n][i]);
}
std::cout << ans << '\n';
}
return 0;
}
|
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int main() {
int n, M=1000000007, tmp, maxc=100;
vector<int> c;
scanf("%d", &n);
int sumc=0;
for(int i=0;i<n;++i) {
scanf("%d", &tmp);
c.push_back(tmp);
sumc+=tmp;
}
int sumb=0, global_bi_over_i_ub=0;
vector<int> b(n, 0);
for(int i=0;i<n-1;++i) {
scanf("%d", &tmp);
sumb = sumb+tmp;
b[i+1] = b[i] + sumb;
global_bi_over_i_ub = min(global_bi_over_i_ub, -(b[i+1] / (i+2)));
}
int global_x_ub = maxc+global_bi_over_i_ub;
int q;
vector<int> x;
scanf("%d", &q);
for(int i=0;i<q;++i) {
scanf("%d", &tmp);
x.push_back(max(global_x_ub-maxc-5, min(global_x_ub+5, tmp)));
}
//printf("ub: %d", global_x_ub);
map<int,int> x2ans;
for(int xval=global_x_ub+5;xval>=global_x_ub-maxc-5;--xval) {
vector<int> *p_ans=nullptr, *p_ans_last=nullptr;
p_ans_last = new vector<int>(sumc+2,0);
(*p_ans_last)[0]=1;
for(int i=0;i<n;++i) {
p_ans = new vector<int>(sumc+2, 0);
int sum_last = 0, lower_bound=xval*(i+1)+b[i];
//printf("lb=%d, xval=%d, mul=%d, b=%d\n", lower_bound, xval, xval*(i+1), b[i]);
for(int j=0;j<=c[i];++j) {
sum_last = (sum_last + (*p_ans_last)[j])%M;
(*p_ans)[j] = sum_last;
}
for(int j=c[i]+1;j<=sumc;++j) {
sum_last = (sum_last - (*p_ans_last)[j-c[i]-1] + M) % M;
sum_last = (sum_last + (*p_ans_last)[j]) % M;
(*p_ans)[j] = sum_last;
}
for(int j=0;j<lower_bound && j<=sumc+1;++j)
(*p_ans)[j]=0;
swap(p_ans, p_ans_last);
delete p_ans;
}
int cnt=0;
for(int i=0;i<=sumc;++i)
cnt = (cnt + (*p_ans_last)[i])%M;
x2ans[xval] = cnt;
delete p_ans_last;
}
for(int i=0;i<q;++i) {
printf("%d\n", x2ans[x[i]]);
}
return 0;
}
|
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif
#define sz(x) ((int) (x).size())
#define TASK "text"
const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);
#ifdef DEBUG
mt19937 mrand(300);
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());
#endif
int rnd(int x) {
return mrand() % x;
}
void precalc() {
}
const int mod = (int) 1e9 + 7;
int mul(int a, int b) {
return (long long) a * b % mod;
}
void add(int &a, int b) {
a += b;
if (a >= mod) {
a -= mod;
}
}
const int maxn = 105;
int n;
int c[maxn], b[maxn];
bool read() {
if (scanf("%d", &n) < 1) {
return false;
}
for (int i = 0; i < n; ++i) {
scanf("%d", &c[i]);
}
for (int i = 0; i + 1 < n; ++i) {
scanf("%d", &b[i]);
}
return true;
}
const int maxx = maxn * maxn;
int dp[maxx], ndp[maxx];
void solve() {
int q;
scanf("%d", &q);
for (int qq = 0; qq < q; ++qq) {
int x;
scanf("%d", &x);
for (int i = 0; i < maxx; ++i) {
dp[i] = 0;
}
dp[0] = 1;
int s = 0;
for (int i = 0; i < n; ++i) {
s += x;
int sum = 0;
for (int j = 0, k = 0; j < maxx; ++j) {
add(sum, dp[j]);
while (j - k > c[i]) {
add(sum, mod - dp[k]);
++k;
}
ndp[j] = (j < s ? 0 : sum);
}
swap(dp, ndp);
if (i + 1 < n) {
x += b[i];
}
}
int res = 0;
for (int i = 0; i < maxx; ++i) {
add(res, dp[i]);
}
printf("%d\n", res);
}
}
int main() {
precalc();
#ifdef DEBUG
assert(freopen(TASK ".in", "r", stdin));
assert(freopen(TASK ".out", "w", stdout));
#endif
while (read()) {
solve();
#ifdef DEBUG
eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
}
return 0;
}
|
/**
* @brief codeforces
* @author yao
*/
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits>
#define ft first
#define sd second
#ifdef DBG
# define dbg_pri(x...) fprintf(stderr,x)
#else
# define dbg_pri(x...) 0
# define NDEBUG
#endif //DBG
#include <cassert>
typedef unsigned int uint;
typedef long long int lli;
typedef unsigned long long int ulli;
#define N 128
#define P ((int)1e9+7)
int c[N];
int b[N];
int s[N];
int dp[N*N];
int main()
{
int n;
scanf("%d", &n);
for(int i=0;i<n;++i) scanf("%d", &c[i]);
for(int i=0;i<n-1;++i) scanf("%d", &b[i]);
int q;
scanf("%d", &q);
for(int qc=0; qc<q; ++qc)
{
int x;
scanf("%d", &x);
s[0] = x;
for(int i=1;i<n;++i) s[i] = s[i-1]+b[i-1];
memset(dp,0,sizeof(dp));
dp[0] = 1;
int tar = 0;
for(int i=0;i<n;++i)
{
for(int j=i*100,ej=std::max(0,tar);j>=ej;--j)if(dp[j])
{
for(int k=j+1,ek=j+c[i];k<=ek;++k)
dp[k] = (dp[k] + dp[j]) % P;
}
tar += s[i];
}
int ans = 0;
for(int i=std::max(0,tar),e=n*100;i<=e;++i)
ans = (ans + dp[i]) %P;
printf("%d\n", ans);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
const int mod = 1000000007;
//const int mod = 998244353;
template<long long MOD>
struct ModInt{
using ll = long long;
ll val;
void setval(ll v) { val = v % MOD; };
ModInt(): val(0) {}
ModInt(ll v) { setval(v); };
ModInt operator+(const ModInt &x) const { return ModInt(val + x.val); }
ModInt operator-(const ModInt &x) const { return ModInt(val - x.val + MOD); }
ModInt operator*(const ModInt &x) const { return ModInt(val * x.val); }
ModInt operator/(const ModInt &x) const { return *this * x.inv(); }
ModInt operator-() const { return ModInt(MOD - val); }
ModInt operator+=(const ModInt &x) { return *this = *this + x; }
ModInt operator-=(const ModInt &x) { return *this = *this - x; }
ModInt operator*=(const ModInt &x) { return *this = *this * x; }
ModInt operator/=(const ModInt &x) { return *this = *this / x; }
bool operator==(const ModInt &x) const { return (*this).val == x.val; }
friend ostream& operator<<(ostream &os, const ModInt &x) { os << x.val; return os; }
friend istream& operator>>(istream &is, ModInt &x) { is >> x.val; x.val = (x.val % MOD + MOD) % MOD; return is; }
ModInt pow(ll n) const {
ModInt a = 1;
if(n == 0) return a;
int i0 = 64 - __builtin_clzll(n);
for(int i = i0 - 1; i >= 0; i--){
a = a * a;
if((n >> i) & 1) a *= (*this);
}
return a;
}
ModInt inv() const { return this->pow(MOD - 2); }
};
using mint = ModInt<mod>; mint pow(mint x, long long n) { return x.pow(n); }
//using mint = double; //for debug
using mvec = vector<mint>;
using mmat = vector<mvec>;
struct Combination{
vector<mint> fact, invfact;
Combination(int N){
fact = vector<mint>({mint(1)});
invfact = vector<mint>({mint(1)});
fact_initialize(N);
}
void fact_initialize(int N){
int i0 = fact.size();
if(i0 >= N + 1) return;
fact.resize(N + 1);
invfact.resize(N + 1);
for(int i = i0; i <= N; i++) fact[i] = fact[i - 1] * i;
invfact[N] = (mint)1 / fact[N];
for(int i = N - 1; i >= i0; i--) invfact[i] = invfact[i + 1] * (i + 1);
}
mint nCr(int n, int r){
if(n < 0 || r < 0 || r > n) return mint(0);
if(fact.size() < n + 1) fact_initialize(n);
return fact[n] * invfact[r] * invfact[n - r];
}
mint nPr(int n, int r){
if(n < 0 || r < 0 || r > n) return mint(0);
if(fact.size() < n + 1) fact_initialize(n);
return fact[n] * invfact[n - r];
}
mint Catalan(int n){
if(n < 0) return 0;
else if(n == 0) return 1;
if(fact.size() < 2 * n + 1) fact_initialize(2 * n);
return fact[2 * n] * invfact[n + 1] * invfact[n];
}
};
signed main(){
int n; cin >> n;
vec c(n); cin >> c;
vec b(n - 1); cin >> b;
int q; cin >> q;
assert(q == 1);
int x; cin >> x;
vec p(n);
p[n - 1] = 0;
IREP(i, n - 1) p[i] = p[i + 1] + b[i];
const int M = 600000;
int th = max(x + p[0], 0LL);
mvec dp(M + 1, 0);
FOR(j, p[0], c[0] + p[0] + 1) if(j >= th) dp[j] = 1;
FOR(i, 1, n){
FOR(j, 1, M + 1) dp[j] += dp[j - 1];
IREP(j, M + 1){
int jmin = j - (p[i] + c[i]), jmax = j - p[i];
mint tmp = 0;
if(jmax >= 0) tmp += dp[jmax];
if(jmin - 1 >= 0) tmp -= dp[jmin - 1];
dp[j] = tmp;
}
REP(j, (i + 1) * th) if(j <= M) dp[j] = 0;
}
mint ans = 0;
REP(j, M + 1) ans += dp[j];
Out(ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 105;
const int MOD = (int)1e9 + 7;
struct mi {
typedef decay<decltype(MOD)>::type T;
/// don't silently convert to T
T v; explicit operator T() const { return v; }
mi() { v = 0; }
mi(ll _v) {
v = (-MOD < _v && _v < MOD) ? _v : _v % MOD;
if (v < 0) v += MOD;
}
friend bool operator==(const mi& a, const mi& b) {
return a.v == b.v; }
friend bool operator!=(const mi& a, const mi& b) {
return !(a == b); }
friend bool operator<(const mi& a, const mi& b) {
return a.v < b.v; }
// friend void re(mi& a) { ll x; re(x); a = mi(x); }
// friend str ts(mi a) { return ts(a.v); }
mi& operator+=(const mi& m) {
if ((v += m.v) >= MOD) v -= MOD;
return *this; }
mi& operator-=(const mi& m) {
if ((v -= m.v) < 0) v += MOD;
return *this; }
mi& operator*=(const mi& m) {
v = (ll)v*m.v%MOD; return *this; }
mi& operator/=(const mi& m) { return (*this) *= inv(m); }
friend mi pow(mi a, ll p) {
mi ans = 1; assert(p >= 0);
for (; p; p /= 2, a *= a) if (p&1) ans *= a;
return ans;
}
friend mi inv(const mi& a) { assert(a.v != 0);
return pow(a,MOD-2); }
mi operator-() const { return mi(-v); }
mi& operator++() { return *this += 1; }
mi& operator--() { return *this -= 1; }
friend mi operator+(mi a, const mi& b) { return a += b; }
friend mi operator-(mi a, const mi& b) { return a -= b; }
friend mi operator*(mi a, const mi& b) { return a *= b; }
friend mi operator/(mi a, const mi& b) { return a /= b; }
};
int n;
int c[N], b[N];
int lb[N], psum[N];
mi dp[N][N * N];
mt19937 rng(2333);
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
rep(i, 1, n + 1) cin >> c[i];
rep(i, 1, n) cin >> b[i];
int q;
cin >> q;
int x; cin >> x;
lb[1] = psum[1] = x;
rep(i, 2, n + 1) {
lb[i] = lb[i - 1] + b[i - 1];
psum[i] = lb[i] + psum[i - 1];
}
dp[0][0] = 1;
int maxs = 100 * n;
rep(i, 1, n + 1) {
rep(s, psum[i], maxs + 1) {
rep(cur, 0, min(s + 1, c[i] + 1)) {
dp[i][s] += dp[i - 1][s - cur];
}
}
}
mi res = 0;
rep(i, 0, maxs + 1) res += dp[n][i];
cout << int(res) << endl;
}
|
/*~Rainybunny~*/
#include <cstdio>
#include <cstring>
#define rep( i, l, r ) for ( int i = l, rep##i = r; i <= rep##i; ++i )
#define per( i, r, l ) for ( int i = r, per##i = l; i >= per##i; --i )
const int MAXN = 101, MOD = 1e9 + 7;
int n, c[MAXN + 5], b[MAXN + 5];
int sc[MAXN + 5], sb[MAXN + 5], sb2[MAXN + 5];
int h[MAXN + 5], ans[MAXN + 5];
inline void chkmax( int& a, const int b ) { a < b && ( a = b ); }
inline int imin( const int a, const int b ) { return a < b ? a : b; }
inline int imax( const int a, const int b ) { return a < b ? b : a; }
inline int sub( int a, const int b ) { return ( a -= b ) < 0 ? a + MOD : a; }
inline int add( int a, const int b ) { return ( a += b ) < MOD ? a : a - MOD; }
inline int solve( const int lim ) {
static int f[MAXN * MAXN + 5], g[MAXN * MAXN + 5];
memset( f, 0, sizeof f ), f[0] = 1;
rep ( i, 1, n ) {
g[0] = f[0];
rep ( j, 1, sc[i] ) g[j] = add( g[j - 1], f[j] );
rep ( j, 0, lim * i + sb[i - 1] - 1 ) f[j] = 0;
rep ( j, imax( 0, lim * i + sb[i - 1] ), sc[i] ) {
f[j] = sub( g[j], j > c[i] ? g[j - c[i] - 1] : 0 );
}
}
int ret = 0;
rep ( i, imax( 0, lim * n + sb[n - 1] ), sc[n] ) ret = add( ret, f[i] );
return ret;
}
int main() {
scanf( "%d", &n );
rep ( i, 1, n ) scanf( "%d", &c[i] ), sc[i] = sc[i - 1] + c[i];
rep ( i, 1, n - 1 ) scanf( "%d", &b[i] );
int mx = 0xcfcfcfcf;
rep ( i, 1, n ) sb[i] = sb[i - 1] + b[i];
rep ( i, 1, n ) sb[i] += sb[i - 1];
rep ( i, 1, n ) chkmax( mx, ( sb[i - 1] + i - 1 ) / i );
rep ( i, 0, MAXN ) ans[i] = solve( i - mx );
int q, x; scanf( "%d", &q );
while ( q-- ) {
scanf( "%d", &x ), x = imin( MAXN - mx, imax( x, -mx ) );
printf( "%d\n", ans[x + mx] );
}
return 0;
}
|
#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;
int C[101];
int B[101],S[101];
int Q;
int X;
const ll mo=1000000007;
ll from[10101][2];
ll to[10101][2];
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N;
FOR(i,N) cin>>C[i];
FOR(i,N-1) {
cin>>x;
B[i+1]=B[i]+x;
S[i+1]=S[i]+B[i+1];
}
cin>>Q;
while(Q--) {
cin>>X;
from[0][0]=1;
FOR(i,N) {
ZERO(to);
FOR(x,100*i+1) if(from[x][0]||from[x][1]) {
FOR(y,C[i]+1) {
(to[x+y][1]+=from[x][1])%=mo;
if(x+y-S[i]-X*(i+1)<0) (to[x+y][1]+=from[x][0])%=mo;
else (to[x+y][0]+=from[x][0])%=mo;
}
}
swap(from,to);
}
ll ret=0;
FOR(i,10100) ret+=from[i][0];
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;
}
|
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define x first
#define y second
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x,T y){x<y?x=y:T();}
template <typename T> void chkmin(T &x,T y){y<x?x=y:T();}
template <typename T> void readint(T &x)
{
x=0;int f=1;char c;
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
for(;isdigit(c);c=getchar())x=x*10+(c-'0');
x*=f;
}
const int MOD=1000000007;
inline int dmy(int x){return x>=MOD?x-MOD:x;}
inline void inc(int &x,int y){x=dmy(x+y);}
int qmi(int x,int y)
{
int ans=1;
for(;y;y>>=1,x=1ll*x*x%MOD)
if(y&1)ans=1ll*ans*x%MOD;
return ans;
}
const int MAXN=105;
int n,m,c[MAXN],b[MAXN],x[MAXN];
int f[MAXN][MAXN*MAXN];
int main()
{
#ifdef LOCAL
freopen("code.in","r",stdin);
// freopen("code.out","w",stdout);
#endif
readint(n);
for(int i=1;i<=n;++i)readint(c[i]);
for(int i=2;i<=n;++i)readint(b[i]),b[i]+=b[i-1];
readint(m);
for(int i=1;i<=m;++i)readint(x[i]);
int sum=0,pre=0;
f[0][0]=1;
for(int i=1;i<=n;++i)
{
for(int j=max(sum,0);j<=pre;++j)
for(int k=0;k<=c[i];++k)
inc(f[i][j+k],f[i-1][j]);
sum+=b[i]+x[1];
pre+=c[i];
}
int res=0;
for(int j=max(sum,0);j<=pre;++j)
inc(res,f[n][j]);
printf("%d\n",res);
return 0;
}
|
// Bhagya Kamal Jain
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define endl '\n'
#define mii map<ll int,ll int>
#define pii pair<ll int,ll int>
#define vi vector<ll int>
#define all(a) (a).begin(),(a).end()
#define F first
#define S second
#define hell 1000000007
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
using namespace std;
sim > struct rge {c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cout << *x, 0);
sim > char dud(...);
struct debug
{
~debug()
{
cout<<endl;
}
eni(!=) cout << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d)
{
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
};
#define fuck(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define N 10005
ll int dp[N];
ll int tmp[N];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int TESTS=1;
// cin>>TESTS;
while(TESTS--)
{
ll int n;
cin >> n;
ll int c[n + 1];
for(ll int i = 1; i <= n; i++) cin >> c[i];
ll int b[n];
for(ll int i = 1; i < n; i++) cin >> b[i];
ll int q;
cin >> q;
while(q--)
{
ll int x;
cin >> x;
ll int arr[n + 1];
arr[1] = x;
for(ll int i = 2; i <= n; i++)
{
arr[i] = arr[i - 1] + b[i - 1];
}
ll int val[n + 1];
val[0] = 0;
for(ll int i = 1; i <= n; i++)
{
val[i] = val[i - 1] + arr[i];
}
dp[0] = 1;
for(ll int i = 1; i <= n; i++)
{
for(ll int j = 0; j < N; j++)
{
tmp[j] = dp[j];
}
memset(dp, 0, sizeof(dp));
for(ll int j = 0; j < N; j++)
{
for(ll int k = 0; k <= c[i]; k++)
{
if(k + j < N) dp[k + j] = (dp[k + j] + tmp[j]) % hell;
}
}
for(ll int j = 0; j < N; j++)
{
if(j < val[i]) dp[j] = 0;
}
}
ll int ans = 0;
for(ll int j = 0; j < N; j++)
{
ans = (ans + dp[j]) % hell;
}
cout << ans << endl;
}
}
return 0;
}
|
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <random>
#include <iomanip>
#include <clocale>
#include <bitset>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
using namespace std;
#define endl '\n'
#define int long long
const int MOD = 1000000007;
const int INF = 2000000000;
const int MAXN = 100000;
int dp[100][20000];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> c(n);
for (int i = 0; i < n; i++) {
cin >> c[i];
}
vector<int> b(n);
for (int i = 1; i < n; i++) {
cin >> b[i];
}
vector<int> bp(n);
for (int i = 1; i < n; i++) {
bp[i] = bp[i - 1] + b[i];
}
for (int i = 1; i < n; i++) {
bp[i] += bp[i - 1];
}
int q;
cin >> q;
for (int _ = 0; _ < q; _++) {
int x;
cin >> x;
vector<int> need(n);
for (int i = 0; i < n; i++) {
need[i] = bp[i] + x * (i + 1);
}
for (int i = 0; i < 100; i++) {
for (int j = 0; j <= 10000; j++) {
dp[i][j] = 0;
}
}
for (int i = max(0LL, need[0]); i <= c[0]; i++) {
dp[0][i] = 1;
}
for (int i = 1; i < n; i++) {
for (int j = need[i]; j <= 10000; j++) {
for (int k = 0; k <= c[i]; k++) {
if (j < k) {
break;
}
dp[i][j] += dp[i - 1][j - k];
if (dp[i][j] >= MOD) {
dp[i][j] -= MOD;
}
}
}
}
int ans = 0;
for (int j = 0; j <= 10000; j++) {
ans += dp[n - 1][j];
}
cout << ans % MOD;
}
}
|
#include<bits/stdc++.h>
namespace my_std{
using namespace std;
#define pii pair<int,int>
#define fir first
#define sec second
#define MP make_pair
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define drep(i,x,y) for (int i=(x);i>=(y);i--)
#define go(x) for (int i=head[x];i;i=edge[i].nxt)
#define templ template<typename T>
#define sz 111
#define mod 1000000007ll
typedef long long ll;
typedef double db;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
templ inline void read(T& t)
{
t=0;char f=0,ch=getchar();double d=0.1;
while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
t=(f?-t:t);
}
template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
char __sr[1<<21],__z[20];int __C=-1,__zz=0;
inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
inline void print(int x)
{
if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
while(__z[++__zz]=x%10+48,x/=10);
while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
}
void file()
{
#ifdef NTFOrz
freopen("a.in","r",stdin);
#endif
}
inline void chktime()
{
#ifdef NTFOrz
cerr<<clock()/1000.0<<'\n';
#endif
}
#ifdef mod
ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
ll inv(ll x){return ksm(x,mod-2);}
#else
ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
#endif
// inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;
int n;
int c[sz],b[sz],B[sz];
ll pre[sz][sz*sz],pr;
void init()
{
pre[0][0]=1;
rep(i,0,n-1) rep(k,0,100*i) rep(t,0,c[i+1]) (pre[i+1][k+t]+=pre[i][k])%=mod;
pr=1; rep(i,1,n) pr=pr*(c[i]+1)%mod;
}
ll dp[sz][sz*sz];
ll work(int x)
{
static int lim[sz];
rep(i,1,n) lim[i]=i*x+B[i];
int p=1; while (p<=n&&lim[p]<=0) ++p; if (p>n) return pr;
rep(i,p,n) rep(j,0,i*100) dp[i][j]=0; rep(i,lim[p],p*100) dp[p][i]=pre[p][i];
rep(i,p,n-1)
{
rep(k,lim[i],i*100) { int l=k,r=k+c[i+1]; if (r<lim[i+1]) continue; chkmax(l,lim[i+1]); dp[i+1][l]+=dp[i][k],dp[i+1][r+1]+=mod-dp[i][k]; }
dp[i+1][lim[i+1]]%=mod;
rep(k,lim[i+1]+1,(i+1)*100) (dp[i+1][k]+=dp[i+1][k-1])%=mod;
}
ll res=0; rep(i,lim[n],n*100) res+=dp[n][i]; return res%mod;
}
int main()
{
file();
read(n);
rep(i,1,n) read(c[i]);
rep(i,2,n) read(b[i]),B[i]=b[i]+B[i-1]; rep(i,2,n) B[i]+=B[i-1];
init();
int Q; read(Q); map<int,ll>vis;
while (Q--)
{
int x; read(x);
if (x>100) { puts("0"); continue; }
if (x<-6000) { printf("%lld\n",pr); continue; }
if (vis.count(x)) { printf("%lld\n",vis[x]); continue; }
ll ans=work(x); printf("%lld\n",vis[x]=ans);
}
return 0;
}
|
#include <bits/stdc++.h>
// #pragma GCC optimize("trapv")
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m";
void DBG() { cerr << "]" << _reset << endl; }
template<class H, class...T> void DBG(H h, T ...t) {
cerr << to_string(h);
if(sizeof ...(t)) cerr << ", ";
DBG(t...);
}
#ifdef CHEISSMART
#define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define debug(...)
#endif
const int INF = 1e9 + 7, N = 105, M = 1e9 + 7;
int c[N], b[N], at_least[N], dp[N][N*N];
void add(int& a, int b) {
a += b;
if(a >= M) a -= M;
}
signed main()
{
IO_OP;
mt19937 rng(time(0));
int n;
cin >> n;
// n = 100;
for(int i = 1; i <= n; i++) {
cin >> c[i];
// c[i] = rng() % 101;
}
for(int i = 1; i <= n - 1; i++) {
cin >> b[i];
// b[i] = rng() % 101;
}
int q, x;
cin >> q >> x;
// q = 1, x = rng() % int(2e5) - 1e5;
assert(q == 1);
for(int i = 1; i <= n; i++) {
at_least[i] = i * x;
for(int j = 1; j <= i; j++)
for(int k = 1; k < j; k++)
at_least[i] += b[k];
at_least[i] = max(at_least[i], 0);
}
dp[0][0] = 1;
for(int i = 0; i < n; i++) {
for(int j = at_least[i]; j < N * N; j++) if(dp[i][j]) {
int need = max(at_least[i + 1] - j, 0);
for(int k = need; k <= c[i + 1]; k++) {
add(dp[i + 1][j + k], dp[i][j]);
}
}
}
int ans = 0;
for(int j = 0; j < N * N; j++)
add(ans, dp[n][j]);
cout << ans << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)
const int MN = 105, MOD = 1e9 + 7;
int n, a[MN], b[MN], c[MN], psa[MN], psum[MN], q, x, dp[12000005], ndp[12000005];
int32_t main() {
boost();
cin >> n;
for (int i = 1; i <= n; i++) cin >> c[i], psa[i] = psa[i - 1] + c[i];
for (int i = 1; i < n; i++) cin >> b[i];
cin >> q >> x;
int sum = 0;
a[1] = x;
for (int i = 2; i <= n; i++) a[i] = a[i - 1] + b[i - 1];
for (int i = 1; i <= n; i++) sum += a[i], psum[i] = psum[i - 1] + a[i];
//printf("%lld\n", sum);
//if (x > c[1]) return 0 * printf("0\n");
int ans = 0;
dp[0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= psa[i - 1]; j++) {
int lo = 0, hi = c[i];
//if (i == 1) lo = max(lo, x);
ndp[j + lo] += dp[j];
ndp[j + lo] %= MOD;
ndp[j + hi + 1] -= dp[j];
ndp[j + hi + 1] %= MOD;
}
for (int j = 1; j <= psa[i]; j++) {
ndp[j] += ndp[j - 1];
ndp[j] %= MOD;
}
for (int j = 0; j <= psa[i]; j++) {
dp[j] = ndp[j];
if (j < psum[i]) dp[j] = 0;
}
//printf("\n");
for (int j = 0; j <= psa[i] + 1; j++) {
ndp[j] = 0;
}
}
for (int i = 0; i <= psa[n]; i++) ans += dp[i], ans %= MOD;
ans %= MOD, ans += MOD, ans %= MOD;
printf("%lld\n", ans);
return 0;
}
|
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
#define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
#define DEBUG(...)
#endif
int MOD = 1e9+7;/*}}}*/
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
const int SIZE = 1<<20;
int c[SIZE],b[SIZE];
int n;
LL dp[SIZE];
LL bk_num[SIZE];
void solve() {
int q;
R(q);
bk_num[n]=1;
for(int i=n-1;i>=0;i--){
bk_num[i]=bk_num[i+1]*(c[i+1]+1)%MOD;
}
while(q--){
int x;
R(x);
LL an=0;
dp[0]=1;
int now=0;
LL sb=0;
LL d=0;
FOR(i,1,n){
for(int j=now;j>=0;j--){
if(dp[j]){
LL me=dp[j];
dp[j]=0;
for(int k=c[i];k>=0;k--){
int v=j+k;
if(i*x+d>v){
ADD(an,bk_num[i]*me);
}else{
ADD(dp[j+k],me);
}
}
}
}
now+=c[i];
sb+=b[i];
d+=sb;
}
an=bk_num[0]-an;
ADD(an,0);
W(an);
}
}
void input() {
R(n);
FOR(i,1,n)R(c[i]);
FOR(i,1,n-1)R(b[i]);
}
int main(){
input();
solve();
return 0;
}
|
/*
Author: QAQAutoMaton
Lang: C++
Code: C1.cpp
Mail: lk@qaq-am.com
Blog: https://www.qaq-am.com/
*/
#include<bits/stdc++.h>
#define debug(qaq...) fprintf(stderr,qaq)
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
#define x first
#define y second
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<double> cp;
typedef pair<int,int> pii;
int inf;
const double eps=1e-8;
const double pi=acos(-1.0);
template<class T,class T2>int chkmin(T &a,T2 b){return a>b?a=b,1:0;}
template<class T,class T2>int chkmax(T &a,T2 b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T,class T2>T mmin(T a,T2 b){return a<b?a:b;}
template<class T,class T2>T mmax(T a,T2 b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
template<class T>int dcmp(T a,T b){return a>b;}
template<int *a>int cmp_a(int x,int y){return a[x]<a[y];}
template<class T>bool sort2(T &a,T &b){return a>b?swap(a,b),1:0;}
#define min mmin
#define max mmax
#define abs aabs
struct __INIT__{
__INIT__(){
fill((unsigned char*)&inf,(unsigned char*)&inf+sizeof(inf),0x3f);
}
}__INIT___;
namespace io {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
// getchar
#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
// print the remaining part
inline void flush () {
fwrite (obuf, 1, oS - obuf, stdout);
oS = obuf;
}
// putchar
inline void putc (char x) {
*oS ++ = x;
if (oS == oT) flush ();
}
template<typename A>
inline bool read (A &x) {
for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;else if(c==EOF)return 0;
for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
return 1;
}
inline bool read (char &x) {
while((x=gc())==' '||x=='\n' || x=='\r');
return x!=EOF;
}
inline bool read(char *x){
while((*x=gc())=='\n' || *x==' '||*x=='\r');
if(*x==EOF)return 0;
while(!(*x=='\n'||*x==' '||*x=='\r'||*x==EOF))*(++x)=gc();
*x=0;
return 1;
}
template<typename A,typename ...B>
inline bool read(A &x,B &...y){
return read(x)&&read(y...);
}
template<typename A>
inline bool write (A x) {
if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
while (x) qu[++ qr] = x % 10 + '0', x /= 10;
while (qr) putc (qu[qr --]);
return 0;
}
inline bool write (char x) {
putc(x);
return 0;
}
inline bool write(const char *x){
while(*x){putc(*x);++x;}
return 0;
}
inline bool write(char *x){
while(*x){putc(*x);++x;}
return 0;
}
template<typename A,typename ...B>
inline bool write(A x,B ...y){
return write(x)||write(y...);
}
//no need to call flush at the end manually!
struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: read;
using io :: putc;
using io :: write;
const int p=1000000007;
struct Z{
uint x;
Z(){}
Z(uint a){
x=a;
}
};
inline uint modp(const uint x){
return x<p?x:x-p;
}
inline Z operator+(const Z x1, const Z x2) { return modp(x1.x+x2.x);}
inline Z operator-(const Z x1, const Z x2) { return modp(x1.x+p-x2.x);}
inline Z operator-(const Z x) {return x.x?p-x.x:0;}
inline Z operator*(const Z x1, const Z x2) { return static_cast<ull>(x1.x)*x2.x%p;}
void exgcd(int a,int b,int &x,int &y){
if(!b){x=1;y=0;return;}
exgcd(b,a%b,y,x);
y-=(a/b)*x;
}
inline Z Inv(const Z a){
int x,y;
exgcd(p,a.x,x,y);
return y<0?y+=p:y;
}
inline Z operator/(const Z x1, const Z x2) { return x1*Inv(x2);}
inline Z &operator++(Z &x1){x1.x==p-1?x1.x=0:++x1.x;return x1;}
inline Z &operator--(Z &x1){x1.x?--x1.x:x1.x=p-1;return x1;}
inline Z &operator+=(Z &x1, const Z x2) { return x1 = x1 + x2; }
inline Z &operator-=(Z &x1, const Z x2) { return x1 = x1 - x2; }
inline Z &operator*=(Z &x1, const Z x2) { return x1 = x1 * x2; }
inline Z &operator/=(Z &x1, const Z x2) { return x1 = x1 / x2; }
inline Z fpm(Z a,int b){Z c(1);for(;b;b>>=1,a*=a)if(b&1)c*=a;return c;}
int c[105],b[105];
Z f[10005],g[10005];
int w[105];
signed main(){
#ifdef QAQAutoMaton
freopen("C1.in","r",stdin);
freopen("C1.out","w",stdout);
#endif
int n;
read(n);
int l=0;
for(int i=1;i<=n;++i){
read(c[i]);
}
for(int i=l;~i;--i)f[i]+=f[i+1];
for(int i=1;i<n;++i){
read(b[i]);
}
int ss=0;
for(int i=2;i<=n;++i){
ss+=b[i-1];
w[i]=w[i-1]+ss;
}
int q;
read(q);
int x;
for(;q;--q){
read(x);
for(int i=0;i<=l;++i)f[i]=0;
f[0]=1;
l=0;
for(int i=1;i<=n;++i){
g[0]=f[0];
l+=c[i];
for(int j=1;j<=l;++j)g[j]=f[j]+g[j-1];
for(int j=0;j<=l;++j){
f[j]=g[j]-(j>c[i]?g[j-c[i]-1]:0);
}
for(int j=0;j<=l;++j){
if(x*i+w[i]>j)f[j]=0;
}
}
Z ans(0);
for(int i=0;i<=l;++i)ans+=f[i];
write(ans.x,'\n');
}
return 0;
}
|
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
inline int addmod(int x)
{
return x>=mod?x-mod:x;
}
inline int submod(int x)
{
return x<0?x+mod:x;
}
int n,m,q,b[105],c[105],sum[105],f[105][10005],qans[1005],pn;
int solve(int x)
{
memset(f,0,sizeof(f));
f[0][0]=1;
int nw=0,ans=0;
for(int i=1;i<=n;i++)
{
for(int j=0;j<=nw;j++)
{
f[i][j]=addmod(f[i][j]+f[i-1][j]);
f[i][j+c[i]+1]=submod(f[i][j+c[i]+1]-f[i-1][j]);
}
nw+=c[i];
for(int j=1;j<=nw;j++)
f[i][j]=addmod(f[i][j]+f[i][j-1]);
for(int j=0;j<x*i+sum[i];j++)
f[i][j]=0;
}
for(int i=0;i<=nw;i++)
ans=addmod(ans+f[n][i]);
return ans;
}
int main()
{
scanf("%d",&n);
int mul=1;
for(int i=1;i<=n;i++)
{
scanf("%d",&c[i]);
m=max(m,c[i]);
mul=1ll*mul*(c[i]+1)%mod;
}
for(int i=1;i<n;i++)
scanf("%d",&b[i]);
for(int i=1;i<=n;i++)
for(int j=1;j<i;j++)
sum[i]+=(i-j)*b[j];
pn=(-sum[n])/n;
for(int i=0;i<=m;i++)
qans[i]=solve(i+pn);
scanf("%d",&q);
for(int i=1;i<=q;i++)
{
int x;
scanf("%d",&x);
if(x<pn) printf("%d\n",mul);
else if(x>pn+m) printf("0\n");
else printf("%d\n",qans[x-pn]);
}
return 0;
}
|
#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <cmath>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <climits>
#include <set>
#include <unordered_map>
#include <time.h>
#include <map>
#include <stack>
#include <unordered_set>
#include <bitset>
#define hash hassh
using namespace std;
int c[105],b[105];
long long dp[105][10005];
int preb[105];
int main() {
int T = 1;
//cin >> T;
while (T--) {
int n,q,x;
cin>>n;
for(int i=1;i<=n;i++) cin>>c[i];
for(int i=1;i<n;i++) cin>>b[i];
cin>>q>>x;
for(int i=2;i<=n;i++){
preb[i]=preb[i-1];
for(int j=1;j<i;j++) preb[i]+=b[j];
}
long long ans=0,mod=1000000007;
dp[0][0]=1;
for(int i=1;i<=n;i++){
int mn=i*x+preb[i];
for(int j=max(mn,0);j<=i*100;j++){
for(int k=0;k<=c[i];k++)
if(j>=k)
dp[i][j]+=dp[i-1][j-k],dp[i][j]%=mod;
if(i==n) ans+=dp[i][j],ans%=mod;
}
}
printf("%lld\n",ans);
}
return 0;
}
//注意检查边界
//注意考虑某些数组/向量可能为空 可能引起错误
//注意各种边界是0还是1
//注意少加不必要的限制条件 避免出错
//不要把前期题想得太难,尝试找简单结论
//想想直接套路化dp行不行!
//求倍增要一层一层求不要一项一项求!!!!
|
#include <bits/stdc++.h>
using namespace std;
static struct FastInput {
static constexpr int BUF_SIZE = 1 << 20;
char buf[BUF_SIZE];
size_t chars_read = 0;
size_t buf_pos = 0;
FILE *in = stdin;
char cur = 0;
inline char get_char() {
if (buf_pos >= chars_read) {
chars_read = fread(buf, 1, BUF_SIZE, in);
buf_pos = 0;
buf[0] = (chars_read == 0 ? -1 : buf[0]);
}
return cur = buf[buf_pos++];
}
inline void tie(int) {}
inline explicit operator bool() {
return cur != -1;
}
inline static bool is_blank(char c) {
return c <= ' ';
}
inline bool skip_blanks() {
while (is_blank(cur) && cur != -1) {
get_char();
}
return cur != -1;
}
inline FastInput& operator>>(char& c) {
skip_blanks();
c = cur;
return *this;
}
inline FastInput& operator>>(string& s) {
if (skip_blanks()) {
s.clear();
do {
s += cur;
} while (!is_blank(get_char()));
}
return *this;
}
template <typename T>
inline FastInput& read_integer(T& n) {
// unsafe, doesn't check that characters are actually digits
n = 0;
if (skip_blanks()) {
int sign = +1;
if (cur == '-') {
sign = -1;
get_char();
}
do {
n += n + (n << 3) + cur - '0';
} while (!is_blank(get_char()));
n *= sign;
}
return *this;
}
template <typename T>
inline typename enable_if<is_integral<T>::value, FastInput&>::type operator>>(T& n) {
return read_integer(n);
}
#if !defined(_WIN32) || defined(_WIN64)
inline FastInput& operator>>(__int128& n) {
return read_integer(n);
}
#endif
template <typename T>
inline typename enable_if<is_floating_point<T>::value, FastInput&>::type operator>>(T& n) {
// not sure if really fast, for compatibility only
n = 0;
if (skip_blanks()) {
string s;
(*this) >> s;
sscanf(s.c_str(), "%lf", &n);
}
return *this;
}
} fast_input;
#define cin fast_input
static struct FastOutput {
static constexpr int BUF_SIZE = 1 << 20;
char buf[BUF_SIZE];
size_t buf_pos = 0;
static constexpr int TMP_SIZE = 1 << 20;
char tmp[TMP_SIZE];
FILE *out = stdout;
inline void put_char(char c) {
buf[buf_pos++] = c;
if (buf_pos == BUF_SIZE) {
fwrite(buf, 1, buf_pos, out);
buf_pos = 0;
}
}
~FastOutput() {
fwrite(buf, 1, buf_pos, out);
}
inline FastOutput& operator<<(char c) {
put_char(c);
return *this;
}
inline FastOutput& operator<<(const char* s) {
while (*s) {
put_char(*s++);
}
return *this;
}
inline FastOutput& operator<<(const string& s) {
for (int i = 0; i < (int) s.size(); i++) {
put_char(s[i]);
}
return *this;
}
template <typename T>
inline char* integer_to_string(T n) {
// beware of TMP_SIZE
char* p = tmp + TMP_SIZE - 1;
if (n == 0) {
*--p = '0';
} else {
bool is_negative = false;
if (n < 0) {
is_negative = true;
n = -n;
}
while (n > 0) {
*--p = (char) ('0' + n % 10);
n /= 10;
}
if (is_negative) {
*--p = '-';
}
}
return p;
}
template <typename T>
inline typename enable_if<is_integral<T>::value, char*>::type stringify(T n) {
return integer_to_string(n);
}
#if !defined(_WIN32) || defined(_WIN64)
inline char* stringify(__int128 n) {
return integer_to_string(n);
}
#endif
template <typename T>
inline typename enable_if<is_floating_point<T>::value, char*>::type stringify(T n) {
sprintf(tmp, "%.17f", n);
return tmp;
}
template <typename T>
inline FastOutput& operator<<(const T& n) {
auto p = stringify(n);
for (; *p != 0; p++) {
put_char(*p);
}
return *this;
}
} fast_output;
// here puts define
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define rint register int
#define rll register ll
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fors(i, a, b) for (ll i = (a); i <= (b); ++i)
#define _fors(i, a, b) for (ll i = (a); i >= (b); --i)
#define cyc(m) fors(rqtwqtqwt, 1, m)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define mem(A, b) memset(A, b, sizeof(A))
#define all(X) (X).begin(), (X).end()
#define y0 gawgfawgawg
#define y1 sdfyseyegeh
#define pb push_back
#define eb emplace_back
#define cout fast_output
#define endl '\n'
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define int long long
int start_time;
const int _ = 105;
const int mod = 1e9 + 7;
const int inv2 = (mod + 1) / 2;
inline int add(int a, int b) {
return (((a + b) % mod) + mod) % mod;
}
inline int mul(int a, int b) {
return 1ll * a * b % mod;
}
int n, q;
int b[_], c[_];
int dp[_*_], s[_*_];
int sum[_];
int m;
void solve() {
cin >> n;
fors(i, 1, n) cin >> c[i];
fors(i, 1, n - 1) cin >> b[i];
fors(i, 2, n) {
sum[i] = sum[i-1];
fors(j, 1, i - 1) sum[i] += b[j];
}
// cout << '*' << m << endl;
cin >> q;
while (q--) {
int xx;
cin >> xx;
dp[0] = 1;
fors(i, 0, 10000) s[i] = 1;
fors(id, 1, n) {
fors(i, 0, 10000) {
if (i <= c[id]) dp[i] = s[i];
else dp[i] = add(s[i], -s[i-c[id]-1]);
}
fors(i, 0, min(10000ll, id * xx + sum[id] - 1)) dp[i] = 0;
s[0] = dp[0];
fors(i, 1, 10000) s[i] = add(s[i-1], dp[i]);
}
cout << s[10000] << endl;
}
return ;
}
signed main() {
#ifdef Sakuyalove
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
start_time = clock();
int T = 1;
// cin >> T;
while (T--) {
solve();
}
#ifdef Sakuyalove
cout << "time = " << clock() - start_time << endl;
#endif
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
constexpr int MAXN = 100;
constexpr int MOD = 1000000007;
constexpr int MAXTOLERANCE = 10000001; //10001; // really? TODO
int c[MAXN], b[MAXN], magic[MAXN];
int dp1[MAXTOLERANCE], dp2[MAXTOLERANCE];
int coalesce[MAXTOLERANCE+1];
int* const coal=coalesce+MAXTOLERANCE/2;
int32_t main(){
ios_base::sync_with_stdio(false);
int n,q;
cin>>n;
for (int i=0;i<n;++i){
cin>>c[i];
}
for(int i=1;i<n;++i){
cin>>b[i];
}
cin>>q;
for(int j=0;j<q;++j){
int x;
cin>>x;
/*if (x>MAXN){
cout<<0<<'\n';
continue;
}*/
magic[0]=x;
for(int i=1;i<n;++i){
magic[i]=magic[i-1]+b[i];
}
int* prev=dp1+MAXTOLERANCE/2;
fill_n(prev-MAXTOLERANCE/2, MAXTOLERANCE, 0);
prev[x]=1;
int prev_low=x;
int prev_high=x;
int* curr=dp2+MAXTOLERANCE/2;
fill_n(curr-MAXTOLERANCE/2, MAXTOLERANCE, 0);
for(int i=0;i<n-1;++i){
//fill_n(curr-MAXTOLERANCE/2, MAXTOLERANCE, 0);
//fill_n(coal-MAXTOLERANCE/2, MAXTOLERANCE+1, 0);
// TODO: optimize
int coal_low=LLONG_MAX;
int coal_high=LLONG_MIN;
for(int k=prev_low;k<=prev_high;++k){
int start = max(k, 0ll);
if (start <= c[i] && prev[k]>0){
int c_start = min(max(magic[i+1]-(c[i]-k), -MAXTOLERANCE/2), MAXTOLERANCE/2+1);
int c_end = min(max(magic[i+1]-(start-k)+1, -MAXTOLERANCE/2), MAXTOLERANCE/2+1);
coal[c_start]+=prev[k];
coal[c_start]%=MOD;
coal[c_end]+=(MOD-prev[k]);
coal[c_end]%=MOD;
coal_low=min(coal_low,c_start);
coal_high=max(coal_high,c_end-1);
}
/*for(int kk=start;kk<=c[i];++kk){
int ind = magic[i+1]-(kk-k);
if (ind >= -MAXTOLERANCE/2 && ind <= MAXTOLERANCE/2){
curr[ind]+=prev[k];
curr[ind]%=MOD;
}
}*/
}
int cum=0;
for(int k=coal_low;k<=coal_high;++k){
cum+=coal[k];
cum%=MOD;
curr[k]=cum;
}
fill(coal+coal_low,coal+coal_high+2,0);
fill(prev+prev_low, prev+prev_high+1,0);
prev_low=coal_low;
prev_high=coal_high;
swap(prev, curr);
/*for(int k=-10;k<=10;++k){
cout<<' '<<prev[k];
}
cout<<endl;
cout<< prev_low<<' '<<prev_high<<endl;*/
}
int ans=0;
{
//fill_n(curr-MAXTOLERANCE/2, MAXTOLERANCE, 0);
// TODO: optimize
for(int k=-MAXTOLERANCE/2;k<=MAXTOLERANCE/2;++k){
int start = max(k, 0ll);
for(int kk=start;kk<=c[n-1];++kk){
ans+=prev[k];
ans%=MOD;
}
}
}
cout<<ans<<'\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
double n, x, y, p, q, r;
int a;
cin >> n >> x >> y;
p = y / 100;
q = n * p;
r = q - x;
a = r;
if (r > a) {
cout << a + 1;
} else if (a < 0) {
cout << "0";
} else {
cout << a;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
double n, x, y;
cin >> n >> x >> y;
if (y * n / 100 <= x)
cout << 0;
else
cout << ceil(y * n / 100 - x);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
int n, x, y;
cin >> n >> x >> y;
if ((ceil(y * n / 100.0) - x) < 0)
cout << 0 << endl;
else
cout << ceil(y * n / 100.0) - x << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int n, x, y, c = 0;
cin >> n >> x >> y;
double p = ceil((y * n) / 100.00);
p = (int)p;
c = p - x;
if (c <= 0) c = 0;
cout << c;
cout << '\n';
;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
float n, x, y;
cin >> n >> x >> y;
int ans = ceil((y * n / 100) - x);
cout << max(ans, 0);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, y;
while (cin >> n >> x >> y) {
int sum = n * y;
if (sum % 100) sum += 100;
sum /= 100;
sum -= x;
if (sum > 0)
cout << sum << endl;
else
cout << 0 << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, x, y;
scanf("%d", &n);
scanf("%d", &x);
scanf("%d", &y);
int dy = 0;
if ((y * n) % 100 == 0)
dy = ((y * n) / 100);
else
dy = ((y * n) / 100) + 1;
int ans = 0;
if (dy - x <= 0)
ans = 0;
else
ans = dy - x;
printf("%d", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, x, y;
int main() {
scanf("%d%d%d", &n, &x, &y);
int req = (int)ceil((double)(n * y) / 100);
if (req <= x)
printf("%d\n", 0);
else
printf("%d\n", req - x);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int citizens, wizards, percentage, result;
scanf("%d %d %d", &citizens, &wizards, &percentage);
result = ceil((percentage * citizens) / 100.0);
result = max(result - wizards, 0);
printf("%d\n", result);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, y;
cin >> n >> x >> y;
if ((ceil(n * (y / 100.0)) - x) <= 0)
cout << 0 << endl;
else
cout << (ceil(n * (y / 100.0)) - x) << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, y;
cin >> n >> x >> y;
cout << max(0, (n * y + 99) / 100 - x) << endl;
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.