Submission #839236


Source Code Expand

Copy
#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;

using ll=long long;

const ll inf =1LL << 62;
const ll mod=1000000007LL;

inline ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
inline ll ADD(const ll &a, const ll &b,const ll &mod) { return a+b<mod?a+b:a+b-mod;}
inline ll SUB(const ll &a, const ll &b,const ll &mod) { return a-b>=0?a-b:a-b+mod;}
inline ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
inline ll INV(ll a,ll mod){ll x,y;extgcd(a,mod,x,y);return (x%mod+mod)%mod;}
inline ll DIV(const ll &a, const ll &b,const ll &mod) {return MUL(a,INV(b,mod),mod);}
inline ll POW(ll a,ll n,ll mod){ll b=1LL;for(a%=mod;n;a=MUL(a,a,mod),n>>=1)if(n&1) b=MUL(b,a,mod); return b;}

ll a[410],b[410];
ll coef[410][410];
ll sum[410][410];

int n,c;

ll rec(ll i,ll res){
	if(i==n) return res==0;

	ll &ret=coef[i][res];
	if(ret!=-1) return ret;

	ret=0LL;
	rrep(nxt,res+1){
		const ll d=res-nxt;
		ll cur=SUB(sum[b[i]][d],sum[a[i]-1][d],mod);
		ll tar=MUL(cur,rec(i+1,nxt),mod);
		ret=ADD(ret,tar,mod);
	}
	return ret;
}

int main(void){
	rep(i,401) rep(d,401){
		if(i-1>=0) sum[i][d]=sum[i-1][d];
		sum[i][d]=ADD(sum[i][d],POW(i,d,mod),mod);
	}

	cin >> n >> c;
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> b[i];

	rep(i,n)rep(j,c+1) coef[i][j]=-1;
	cout << rec(0,c) << endl;
	return 0;
}

Submission Info

Submission Time
Task E - Children and Candies
User Hec
Language C++14 (GCC 5.4.1)
Score 800
Code Size 2211 Byte
Status AC
Exec Time 380 ms
Memory 2816 KB

Judge Result

Set Name Sample Subtask All
Score / Max Score 0 / 0 400 / 400 400 / 400
Status
AC × 5
AC × 12
AC × 30
Set Name Test Cases
Sample 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt
Subtask 0_001, 0_003, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt
All 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 2_017.txt, 2_018.txt, 2_019.txt, 2_020.txt, 2_021.txt, 2_022.txt, 2_023.txt, 2_024.txt, 2_025.txt, 2_026.txt, 2_027.txt, 2_028.txt, 2_029.txt
Case Name Status Exec Time Memory
0_000.txt AC 17 ms 1536 KB
0_001.txt AC 17 ms 1536 KB
0_002.txt AC 17 ms 1536 KB
0_003.txt AC 17 ms 1536 KB
0_004.txt AC 18 ms 1536 KB
1_005.txt AC 18 ms 1536 KB
1_006.txt AC 18 ms 1536 KB
1_007.txt AC 18 ms 1536 KB
1_008.txt AC 18 ms 1536 KB
1_009.txt AC 18 ms 1536 KB
1_010.txt AC 17 ms 1536 KB
1_011.txt AC 19 ms 2816 KB
1_012.txt AC 20 ms 2816 KB
1_013.txt AC 20 ms 2816 KB
1_014.txt AC 378 ms 2816 KB
1_015.txt AC 378 ms 2816 KB
1_016.txt AC 379 ms 2816 KB
2_017.txt AC 18 ms 1536 KB
2_018.txt AC 17 ms 1536 KB
2_019.txt AC 17 ms 1536 KB
2_020.txt AC 18 ms 1536 KB
2_021.txt AC 19 ms 2816 KB
2_022.txt AC 19 ms 2816 KB
2_023.txt AC 379 ms 2816 KB
2_024.txt AC 380 ms 2816 KB
2_025.txt AC 76 ms 2816 KB
2_026.txt AC 20 ms 2560 KB
2_027.txt AC 303 ms 2688 KB
2_028.txt AC 23 ms 1920 KB
2_029.txt AC 19 ms 1664 KB