Submission #2070720
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp make_pair
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#define INF 1120000000
template<int mod=1000000007>
class ModInt {
int x;
public:
ModInt() : x(0){}
ModInt(int64_t y){ x = y % mod; if(x < 0) x += mod; }
ModInt &operator += (const ModInt &p){ x += p.x; if(x >= mod) x -= mod; return *this; }
ModInt &operator -= (const ModInt &p){ x -= p.x; if(x < 0) x += mod; return *this; }
ModInt &operator *= (const ModInt &p){ x = (int) (1LL * x * p.x % mod); return *this; }
ModInt &operator /= (const ModInt &p){ *this *= p.inverse(); return *this; }
ModInt &operator += (const int64_t y){ x = (x + y)%mod; if(x < 0) x += mod; return *this; }
ModInt &operator -= (const int64_t y){ x = (x - y)%mod; if(x < 0) x += mod; return *this; }
ModInt &operator *= (const int64_t y){ x = (int) (x * y % mod); return *this; }
ModInt &operator /= (const int64_t y){ *this *= ModInt(y).inverse(); return *this; }
ModInt operator -() const { return ModInt(-x); }
ModInt operator + (const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator - (const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator * (const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator / (const ModInt &p) const { return ModInt(*this) /= p; }
bool operator == (const ModInt &p) const { return x == p.x; }
bool operator != (const ModInt &p) const { return x != p.x; }
ModInt operator + (const int64_t y) const { return ModInt(*this) += y; }
ModInt operator - (const int64_t y) const { return ModInt(*this) -= y; }
ModInt operator * (const int64_t y) const { return ModInt(*this) *= y; }
ModInt operator / (const int64_t y) const { return ModInt(*this) /= y; }
bool operator == (const int64_t y) const { return x == (mod + y%mod)%mod; }
bool operator != (const int64_t y) const { return x != (mod + y%mod)%mod; }
ModInt operator = (const int64_t y) { return *this = ModInt(y); }
ModInt inverse() const {
int a = x, b = mod, u = 1, v = 0, t;
while(b > 0){
t = a/b; a -= t*b; swap(a, b);
u -= t*v; swap(u, v);
}
return ModInt(u);
}
friend ostream &operator << (ostream &os, const ModInt<mod> &p) { return os<<p.x; }
friend istream &operator >> (istream &is, ModInt<mod> &a) { int64_t x; is>>x; a = ModInt<mod>(x); return is; }
};
using Int = ModInt<>;
Int tbl[305][305][155];
Int fact[400];
Int finv[400];
int main(){
fact[0] = 1;
rep(i,305) fact[i+1] = fact[i]*(i+1);
rep(i,305) finv[i] = fact[i].inverse();
int n,x,y,z;
cin>>n>>x>>y>>z;
if(x+y+z < n){
cout << 0 << endl;
return 0;
}
rep(c1,301) rep(c2,301) rep(c3,151){
Int &v = tbl[c1][c2][c3];
if(c1+c2<=c3) v = finv[c1] * finv[c2] * finv[c3-c1-c2];
else v = 0;
if(c1>0) v += tbl[c1-1][c2][c3];
if(c2>0) v += tbl[c1][c2-1][c3];
if(c1>0 && c2>0) v -= tbl[c1-1][c2-1][c3];
}
Int ans = 0;
rep(i,x+1) rep(j,y+1) rep(k,z+1){
for(int l=0; i+j+k+l<=n && i+j+l<=x+y; l++){
int c1 = y+z-j-k;
int c2 = x+z-i-k;
int c3 = n-i-j-k-l;
auto sel = fact[n] * finv[i] * finv[j] * finv[k] * finv[l];
ans += sel * tbl[c1][c2][c3];
}
}
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
F - 就職活動 |
User |
tossy |
Language |
C++14 (GCC 5.4.1) |
Score |
100 |
Code Size |
4098 Byte |
Status |
AC |
Exec Time |
231 ms |
Memory |
56704 KB |
Judge Result
Set Name |
Sample |
Subtask1 |
Subtask2 |
Score / Max Score |
0 / 0 |
25 / 25 |
75 / 75 |
Status |
|
|
|
Set Name |
Test Cases |
Sample |
00-sample-00.txt, 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt |
Subtask1 |
01-small-04.txt, 01-small-05.txt, 01-small-06.txt, 01-small-07.txt, 01-small-08.txt, 01-small-09.txt, 01-small-10.txt, 01-small-11.txt, 01-small-12.txt, 01-small-13.txt, 01-small-14.txt, 01-small-15.txt, 01-small-16.txt, 01-small-17.txt, 01-small-18.txt, 01-small-19.txt, 01-small-20.txt, 00-sample-00.txt, 00-sample-01.txt, 00-sample-02.txt |
Subtask2 |
02-large-21.txt, 02-large-22.txt, 02-large-23.txt, 02-large-24.txt, 02-large-25.txt, 02-large-26.txt, 02-large-27.txt, 02-large-28.txt, 02-large-29.txt, 02-large-30.txt, 02-large-31.txt, 02-large-32.txt, 02-large-33.txt, 02-large-34.txt, 02-large-35.txt, 02-large-36.txt, 02-large-37.txt, 02-large-38.txt, 02-large-39.txt, 02-large-40.txt, 02-large-41.txt, 02-large-42.txt, 02-large-43.txt, 02-large-44.txt, 02-large-45.txt, 00-sample-03.txt |
Case Name |
Status |
Exec Time |
Memory |
00-sample-00.txt |
AC |
114 ms |
56576 KB |
00-sample-01.txt |
AC |
114 ms |
56576 KB |
00-sample-02.txt |
AC |
114 ms |
56576 KB |
00-sample-03.txt |
AC |
114 ms |
56576 KB |
01-small-04.txt |
AC |
114 ms |
56704 KB |
01-small-05.txt |
AC |
114 ms |
56576 KB |
01-small-06.txt |
AC |
114 ms |
56576 KB |
01-small-07.txt |
AC |
114 ms |
56576 KB |
01-small-08.txt |
AC |
114 ms |
56576 KB |
01-small-09.txt |
AC |
114 ms |
56576 KB |
01-small-10.txt |
AC |
114 ms |
56576 KB |
01-small-11.txt |
AC |
114 ms |
56576 KB |
01-small-12.txt |
AC |
115 ms |
56576 KB |
01-small-13.txt |
AC |
114 ms |
56576 KB |
01-small-14.txt |
AC |
114 ms |
56576 KB |
01-small-15.txt |
AC |
114 ms |
56576 KB |
01-small-16.txt |
AC |
114 ms |
56576 KB |
01-small-17.txt |
AC |
114 ms |
56576 KB |
01-small-18.txt |
AC |
114 ms |
56576 KB |
01-small-19.txt |
AC |
20 ms |
56576 KB |
01-small-20.txt |
AC |
20 ms |
56576 KB |
02-large-21.txt |
AC |
114 ms |
56576 KB |
02-large-22.txt |
AC |
115 ms |
56576 KB |
02-large-23.txt |
AC |
224 ms |
56576 KB |
02-large-24.txt |
AC |
120 ms |
56704 KB |
02-large-25.txt |
AC |
164 ms |
56576 KB |
02-large-26.txt |
AC |
201 ms |
56576 KB |
02-large-27.txt |
AC |
169 ms |
56576 KB |
02-large-28.txt |
AC |
177 ms |
56576 KB |
02-large-29.txt |
AC |
211 ms |
56576 KB |
02-large-30.txt |
AC |
148 ms |
56576 KB |
02-large-31.txt |
AC |
164 ms |
56576 KB |
02-large-32.txt |
AC |
150 ms |
56576 KB |
02-large-33.txt |
AC |
172 ms |
56576 KB |
02-large-34.txt |
AC |
231 ms |
56576 KB |
02-large-35.txt |
AC |
126 ms |
56576 KB |
02-large-36.txt |
AC |
214 ms |
56576 KB |
02-large-37.txt |
AC |
116 ms |
56576 KB |
02-large-38.txt |
AC |
193 ms |
56576 KB |
02-large-39.txt |
AC |
168 ms |
56576 KB |
02-large-40.txt |
AC |
227 ms |
56576 KB |
02-large-41.txt |
AC |
170 ms |
56576 KB |
02-large-42.txt |
AC |
228 ms |
56576 KB |
02-large-43.txt |
AC |
134 ms |
56576 KB |
02-large-44.txt |
AC |
154 ms |
56576 KB |
02-large-45.txt |
AC |
170 ms |
56576 KB |