結果
問題 | No.584 赤、緑、青の色塗り |
ユーザー |
![]() |
提出日時 | 2017-10-28 12:50:22 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 10 ms / 2,000 ms |
コード長 | 1,986 bytes |
コンパイル時間 | 1,754 ms |
コンパイル使用メモリ | 162,680 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-22 03:04:04 |
合計ジャッジ時間 | 2,368 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 14 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define FOR(i,a,b) for(int i=(a);i<(b);i++)#define REP(i,n) FOR(i,0,n)#define ALL(v) (v).begin(),(v).end()#define fi first#define se secondtemplate<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }typedef long long ll;typedef pair<int, int> pii;typedef pair<ll, ll> pll;typedef pair<pll, int> plp;const ll INF = 1e9+100;const ll MOD = 1e9+7;const double EPS = 1e-10;const bool debug = 0;//--------------------------------//ll mod_pow(ll x, ll n, ll mod) {if (n == 0) return 1;ll res = mod_pow(x * x % mod, n / 2, mod);if (n & 1) res = res * x % mod;return res;}vector<ll> fact, inv;void fact_inv(int n, ll mod) {fact.resize(n + 1);inv.resize(n + 1);fact[0] = 1;FOR(i, 1, n + 1) fact[i] = fact[i - 1] * i % mod;inv[n] = mod_pow(fact[n], mod - 2, mod);for (int i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;}ll ncr(ll n, ll r, ll mod) {if (n < r || r < 0 || n < 0) return 0;return fact[n] * inv[r] % mod * inv[n - r] % mod;}int N, R, G, B;int main() {cin >> N >> R >> G >> B;int all = R + G + B;fact_inv(7000, MOD);ll ans = 0;REP(two, N) {int one = all - 2 * two;if (one < 0) break;int sc = N - one - 2 * two; // 空白マスの個数int m = sc - (one + two - 1); // 自由な空白マスの個数if (sc < 0 || m < 0) continue;ll pat = 0;REP(c, two + 1) { // R?の個数if (c > R) break;int r = R - c, g = G - (two-c), b = B - (two-c);if (g < 0 || b < 0 || r > one) continue;ll now = fact[one+two] * inv[c]%MOD * inv[two-c]%MOD * inv[r]%MOD * inv[one-r]%MOD;now = now * ncr(g+b, g, MOD) % MOD;pat = (pat + now) % MOD;}pat = pat * mod_pow(2, two, MOD) % MOD * ncr(m + one + two, m, MOD) % MOD;ans = (ans + pat) % MOD;}cout << ans << endl;return 0;}