Submission #2169462
Source Code Expand
#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))
using namespace std;
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 ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// Problem Specific Parameter:
template<int MOD> struct ModInt {
static const int Mod = MOD;
unsigned x;
ModInt(): x(0) {}
ModInt(signed sig) {int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
int getval() const { return int(x); }
inline int extgcd(int a, int b, int& x, int& y) {x = 1, y = 0; int g = a; if (b != 0) g = extgcd(b, a % b, y, x), y -= a / b * x; return g;}
ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
ModInt &operator*=(ModInt that) { x = 1LL * x * that.x % MOD; return *this; }
ModInt &operator/=(ModInt that) { int y, d; extgcd(that.x, MOD, y, d); return x = 1LL * x * y % MOD; return *this;}
ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
};
using mint = ModInt<1000000007>;
const int limit = 100000;
mint I[limit + 10];
void inv_table(int n) {I[1] = 1LL; rep(i, 2, n + 1) I[i] = I[mint::Mod % i] * (mint::Mod - mint::Mod / i);}
mint F[limit + 10], IF[limit + 10];
void fact_table(int n) {F[0] = IF[0] = 1LL; rep(i, 1, n + 1) F[i] = F[i - 1] * i, IF[i] = IF[i - 1] * I[i];}
inline mint comb(int n, int k) {return F[n] * IF[k] * IF[n - k];}
void init() {
inv_table(limit);
fact_table(limit);
}
mint dp[5010][5010][2];
int main(void) {
init();
int n, a, b, c;
cin >> n >> a >> b >> c;
dp[0][0][0] = mint(1);
rep(block, n + 1)rep(three, n + 1)rep(state, 2) {
if (dp[block][three][state].getval() == 0) continue;
if (state == 0) {
// 2222
// 232 ... 3333 ... 232 first
dp[block][three][1] += dp[block][three][0];
} else {
// 232 ... 3333 ... 232 middle
dp[block][three + 1][1] += dp[block][three][1];
// 232 ... 3333 ... 232 last
dp[block + 1][three][0] += dp[block][three][1];
}
}
// ca 2222 cb 232232 cc 3333 cd 333333 ce 3113 cf 11
// a = ce + cf
// b = 2 * ca + 2 * cb
// c = cb + 2 * cc + 3 * cd + ce
// block = ca + cb
// three = cb + 2 * cc
mint ans;
rep(three, n + 1)rep(ce, n + 1) {
if (b % 2 != 0) continue;
const int block = b / 2;
if (dp[block][three][0].getval() == 0) continue;
if (a - ce < 0) continue;
const int cf = a - ce;
if (c - three - ce < 0 or (c - three - ce) % 3 != 0) continue;
const int cd = (c - three - ce) / 3;
mint cur = dp[block][three][0];
mint coef = comb(block + cd + ce + cf, block) * comb(cd + ce + cf, cd) * comb(ce + cf, ce);
ans += coef * cur;
}
cout << ans.getval() << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
J - 123 Pairs |
User |
Hec |
Language |
C++14 (GCC 5.4.1) |
Score |
1500 |
Code Size |
4121 Byte |
Status |
AC |
Exec Time |
311 ms |
Memory |
197632 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
1500 / 1500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
example0.txt, example1.txt |
All |
000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, example0.txt, example1.txt |
Case Name |
Status |
Exec Time |
Memory |
000.txt |
AC |
301 ms |
197504 KB |
001.txt |
AC |
288 ms |
197504 KB |
002.txt |
AC |
288 ms |
197504 KB |
003.txt |
AC |
295 ms |
197504 KB |
004.txt |
AC |
288 ms |
197504 KB |
005.txt |
AC |
288 ms |
197504 KB |
006.txt |
AC |
296 ms |
197504 KB |
007.txt |
AC |
279 ms |
197504 KB |
008.txt |
AC |
288 ms |
197504 KB |
009.txt |
AC |
296 ms |
197504 KB |
010.txt |
AC |
277 ms |
197504 KB |
011.txt |
AC |
281 ms |
197504 KB |
012.txt |
AC |
277 ms |
197504 KB |
013.txt |
AC |
65 ms |
197504 KB |
014.txt |
AC |
65 ms |
197504 KB |
015.txt |
AC |
279 ms |
197504 KB |
016.txt |
AC |
84 ms |
197504 KB |
017.txt |
AC |
145 ms |
197504 KB |
018.txt |
AC |
81 ms |
197504 KB |
019.txt |
AC |
169 ms |
197504 KB |
020.txt |
AC |
181 ms |
197504 KB |
021.txt |
AC |
298 ms |
197504 KB |
022.txt |
AC |
237 ms |
197504 KB |
023.txt |
AC |
295 ms |
197504 KB |
024.txt |
AC |
304 ms |
197504 KB |
025.txt |
AC |
296 ms |
197504 KB |
026.txt |
AC |
299 ms |
197504 KB |
027.txt |
AC |
305 ms |
197504 KB |
028.txt |
AC |
297 ms |
197504 KB |
029.txt |
AC |
297 ms |
197504 KB |
030.txt |
AC |
303 ms |
197504 KB |
031.txt |
AC |
305 ms |
197504 KB |
032.txt |
AC |
293 ms |
197504 KB |
033.txt |
AC |
263 ms |
197504 KB |
034.txt |
AC |
172 ms |
197504 KB |
035.txt |
AC |
250 ms |
197504 KB |
036.txt |
AC |
164 ms |
197504 KB |
037.txt |
AC |
60 ms |
197504 KB |
038.txt |
AC |
311 ms |
197504 KB |
039.txt |
AC |
272 ms |
197504 KB |
040.txt |
AC |
272 ms |
197504 KB |
041.txt |
AC |
292 ms |
197504 KB |
042.txt |
AC |
290 ms |
197504 KB |
043.txt |
AC |
60 ms |
197632 KB |
044.txt |
AC |
60 ms |
197504 KB |
045.txt |
AC |
60 ms |
197504 KB |
046.txt |
AC |
60 ms |
197504 KB |
047.txt |
AC |
60 ms |
197504 KB |
048.txt |
AC |
60 ms |
197504 KB |
049.txt |
AC |
60 ms |
197504 KB |
example0.txt |
AC |
60 ms |
197504 KB |
example1.txt |
AC |
64 ms |
197504 KB |