Submission #1001078
Source Code Expand
#include <iostream> #include <iomanip> #include <cstdio> #include <cstdlib> #include <algorithm> #include <numeric> #include <random> #include <vector> #include <array> #include <bitset> #include <queue> #include <set> #include <unordered_set> #include <map> #include <unordered_map> using namespace std; using ll = long long; using ull = unsigned long long; constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); } int bsr(int x) { return 31 - __builtin_clz(x); } template<class T> T pow(T x, ll n, T r = 1) { while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } template<uint MD> struct ModInt { uint v; ModInt() : v{0} {} ModInt(ll v) : v{normS(v%MD+MD)} {} static uint normS(const uint &x) {return (x<MD)?x:x-MD;}; static ModInt make(const uint &x) {ModInt m; m.v = x; return m;} ModInt operator+(const ModInt &r) const {return make(normS(v+r.v));} ModInt operator-(const ModInt &r) const {return make(normS(v+MD-r.v));} ModInt operator*(const ModInt &r) const {return make((ull)v*r.v%MD);} ModInt& operator+=(const ModInt &r) {return *this=*this+r;} ModInt& operator-=(const ModInt &r) {return *this=*this-r;} ModInt& operator*=(const ModInt &r) {return *this=*this*r;} static ModInt inv(const ModInt &x) { return pow(ModInt(x), MD-2); } }; using Mint = ModInt<TEN(9)+7>; using T = tuple<int, int, int, int, int>; map<T, Mint> dp; int n; Mint calc(int p, int a, int b, int c, int f) { if (p == 2*n) { if (f == 0) return 1; return 0; } T key = T(p, a, b, c, f); if (dp.count(key)) { return dp[key]; } // non use Mint ans = 0; if ((f & 4) == 0) { ans += calc(p+1, a, b, c, (f<<1)+1); } // back single if (a && (f & 1)) { ans += calc(p+1, a-1, b, c, (f^1)<<1); } if (b && (f & 2)) { ans += calc(p+1, a, b-1, c, (f^2)<<1); } if (c && (f & 4)) { ans += calc(p+1, a, b, c-1, (f^4)<<1); } return dp[key] = ans; } Mint fact[100000], iFac[100000]; Mint C(int n, int k) { return fact[n]*iFac[k]*iFac[n-k]; } int main() { fact[0] = 1; for (int i = 1; i < 100000; i++) { fact[i] = fact[i-1]*i; } for (int i = 0; i < 100000; i++) { iFac[i] = Mint::inv(fact[i]); } ios::sync_with_stdio(0); cout << setprecision(20); cin >> n; int a, b, c; cin >> a >> b >> c; Mint ans = 0; for (int x = 0; x <= c; x++) { for (int y = 0; y <= c; y++) { int z = a-y; if (z < 0) continue; int nb = b; int nc = c-3*x-y; if (nc < 0) continue; if (nb % 2) continue; int w = nb/2; Mint base = 1; base *= C(x+y+z+w, x); base *= C(y+z+w, y); base *= C(z+w, z); int cu = nc; if (cu && w == 0) continue; if (cu > 0) { base *= C(cu+w-1, cu); } ans += base; } } cout << ans.v << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | J - 123 Pairs |
User | yosupo |
Language | C++14 (GCC 5.4.1) |
Score | 1500 |
Code Size | 3227 Byte |
Status | AC |
Exec Time | 42 ms |
Memory | 1024 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 | 26 ms | 1024 KB |
001.txt | AC | 32 ms | 1024 KB |
002.txt | AC | 15 ms | 1024 KB |
003.txt | AC | 15 ms | 1024 KB |
004.txt | AC | 31 ms | 1024 KB |
005.txt | AC | 15 ms | 1024 KB |
006.txt | AC | 15 ms | 1024 KB |
007.txt | AC | 31 ms | 1024 KB |
008.txt | AC | 15 ms | 1024 KB |
009.txt | AC | 15 ms | 1024 KB |
010.txt | AC | 15 ms | 1024 KB |
011.txt | AC | 15 ms | 1024 KB |
012.txt | AC | 31 ms | 1024 KB |
013.txt | AC | 15 ms | 1024 KB |
014.txt | AC | 15 ms | 1024 KB |
015.txt | AC | 33 ms | 1024 KB |
016.txt | AC | 17 ms | 1024 KB |
017.txt | AC | 20 ms | 1024 KB |
018.txt | AC | 16 ms | 1024 KB |
019.txt | AC | 22 ms | 1024 KB |
020.txt | AC | 17 ms | 1024 KB |
021.txt | AC | 32 ms | 1024 KB |
022.txt | AC | 17 ms | 1024 KB |
023.txt | AC | 18 ms | 1024 KB |
024.txt | AC | 34 ms | 1024 KB |
025.txt | AC | 18 ms | 1024 KB |
026.txt | AC | 24 ms | 1024 KB |
027.txt | AC | 29 ms | 1024 KB |
028.txt | AC | 20 ms | 1024 KB |
029.txt | AC | 22 ms | 1024 KB |
030.txt | AC | 38 ms | 1024 KB |
031.txt | AC | 31 ms | 1024 KB |
032.txt | AC | 16 ms | 1024 KB |
033.txt | AC | 16 ms | 1024 KB |
034.txt | AC | 25 ms | 1024 KB |
035.txt | AC | 23 ms | 1024 KB |
036.txt | AC | 16 ms | 1024 KB |
037.txt | AC | 15 ms | 1024 KB |
038.txt | AC | 42 ms | 1024 KB |
039.txt | AC | 16 ms | 1024 KB |
040.txt | AC | 16 ms | 1024 KB |
041.txt | AC | 28 ms | 1024 KB |
042.txt | AC | 15 ms | 1024 KB |
043.txt | AC | 15 ms | 1024 KB |
044.txt | AC | 15 ms | 1024 KB |
045.txt | AC | 15 ms | 1024 KB |
046.txt | AC | 15 ms | 1024 KB |
047.txt | AC | 15 ms | 1024 KB |
048.txt | AC | 15 ms | 1024 KB |
049.txt | AC | 15 ms | 1024 KB |
example0.txt | AC | 15 ms | 1024 KB |
example1.txt | AC | 15 ms | 1024 KB |