Submission #3855049
Source Code Expand
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;
const ld PI = 4*atan((ld)1);
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
namespace io {
// TYPE ID (StackOverflow)
template<class T> struct like_array : is_array<T>{};
template<class T, size_t N> struct like_array<array<T,N>> : true_type{};
template<class T> struct like_array<vector<T>> : true_type{};
template<class T> bool is_like_array(const T& a) { return like_array<T>::value; }
// I/O
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
ios_base::sync_with_stdio(0); cin.tie(0);
if (sz(s)) { setIn(s+".in"), setOut(s+".out"); }
}
// INPUT
template<class T> void re(T& x) { cin >> x; }
template<class Arg, class... Args> void re(Arg& first, Args&... rest);
void re(double& x) { string t; re(t); x = stod(t); }
void re(ld& x) { string t; re(t); x = stold(t); }
template<class T> void re(complex<T>& x);
template<class T1, class T2> void re(pair<T1,T2>& p);
template<class T> void re(vector<T>& a);
template<class T, size_t SZ> void re(array<T,SZ>& a);
template<class Arg, class... Args> void re(Arg& first, Args&... rest) { re(first); re(rest...); }
template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = cd(a,b); }
template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
template<class T> void re(vector<T>& a) { F0R(i,sz(a)) re(a[i]); }
template<class T, size_t SZ> void re(array<T,SZ>& a) { F0R(i,SZ) re(a[i]); }
// OUTPUT
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) {
os << '{' << a.f << ", " << a.s << '}'; return os;
}
template<class T> ostream& printArray(ostream& os, const T& a, int SZ) {
os << '{';
F0R(i,SZ) {
if (i) {
os << ", ";
if (is_like_array(a[i])) cout << "\n";
}
os << a[i];
}
os << '}';
return os;
}
template<class T, size_t SZ> ostream& operator<<(ostream& os, const array<T,SZ>& a) {
return printArray(os,a,SZ);
}
template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
return printArray(os,a,sz(a));
}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {
os << vector<T>(all(a)); return os;
}
template<class T1, class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {
os << vector<pair<T1,T2>>(all(a)); return os;
}
template<class T> void pr(const T& x) { cout << x << '\n'; }
template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
cout << first << ' '; pr(rest...);
}
}
using namespace io;
namespace modOp {
int ad(int a, int b, int mod = MOD) { return (a+b)%mod; }
int sub(int a, int b, int mod = MOD) { return (a-b+mod)%mod; }
int mul(int a, int b, int mod = MOD) { return (ll)a*b%mod; }
int AD(int& a, int b, int mod = MOD) { return a = ad(a,b,mod); }
int SUB(int& a, int b, int mod = MOD) { return a = sub(a,b,mod); }
int MUL(int& a, int b, int mod = MOD) { return a = mul(a,b,mod); }
int po (int b, int p, int mod = MOD) { return !p?1:mul(po(mul(b,b,mod),p/2,mod),p&1?b:1,mod); }
int inv (int b, int mod = MOD) { return po(b,mod-2,mod); }
int invGeneral(int a, int b) { // 0 < a < b, gcd(a,b) = 1
if (a == 0) return b == 1 ? 0 : -1;
int x = invGeneral(b%a,a);
return x == -1 ? -1 : ((1-(ll)b*x)/a+b)%b;
}
}
using namespace modOp;
template<int SZ> struct combo {
int fac[SZ+1], ifac[SZ+1];
vpl factors;
vi cnt[SZ+1];
void init(ll _MOD) {
factors = {{MOD,1}}; // factors = factor(MOD);
cnt[0].resize(sz(factors));
fac[0] = ifac[0] = 1;
FOR(i,1,SZ+1) {
cnt[i] = cnt[i-1];
int I = i;
F0R(j,sz(factors))
while (I % factors[j].f == 0)
I /= factors[j].f, cnt[i][j] ++;
fac[i] = mul(I,fac[i-1],MOD), ifac[i] = invGeneral(fac[i],MOD);
}
}
ll comb(ll a, ll b) {
if (a == b) return 1;
if (a < b || b < 0) return 0;
ll tmp = mul(mul(fac[a],ifac[b],MOD),ifac[a-b],MOD);
F0R(i,sz(factors)) {
int t = cnt[a][i]-cnt[a-b][i]-cnt[b][i];
tmp = mul(tmp,po(factors[i].f,t),MOD);
}
return tmp;
}
};
combo<5001> Z;
int N,A,B,C,ans;
int multi(vi v) {
int prod = 1, sum = 0;
trav(x,v) {
sum += x;
MUL(prod,Z.ifac[x]);
}
MUL(prod,Z.fac[sum]);
return prod;
}
int main() {
// you should actually read the stuff at the bottom
Z.init(MOD);
setIO(); re(N,A,B,C);
if (B % 2 != 0) {
cout << 0;
exit(0);
}
for (int i = 0; i <= min(A,C); ++i) for (int j = 0; i+3*j <= C; ++j) {
int two = A-i, four = i, six = j, special = B/2;
AD(ans,mul(multi({two,four,six,special}),Z.comb(C-i-3*j+special-1,special-1)));
// C-i-3*j extras
}
pr(ans);
// you should actually read the stuff at the bottom
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?), set tle
* do smth instead of nothing and stay organized
*/
Submission Info
Submission Time |
|
Task |
J - 123 Pairs |
User |
Benq |
Language |
C++14 (GCC 5.4.1) |
Score |
1500 |
Code Size |
6950 Byte |
Status |
AC |
Exec Time |
60 ms |
Memory |
512 KB |
Compile Error
./Main.cpp: In function ‘void io::setIn(std::string)’:
./Main.cpp:67:56: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
^
./Main.cpp: In function ‘void io::setOut(std::string)’:
./Main.cpp:68:58: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
^
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 |
31 ms |
512 KB |
001.txt |
AC |
5 ms |
512 KB |
002.txt |
AC |
5 ms |
512 KB |
003.txt |
AC |
5 ms |
512 KB |
004.txt |
AC |
5 ms |
512 KB |
005.txt |
AC |
5 ms |
512 KB |
006.txt |
AC |
5 ms |
512 KB |
007.txt |
AC |
5 ms |
512 KB |
008.txt |
AC |
5 ms |
512 KB |
009.txt |
AC |
5 ms |
512 KB |
010.txt |
AC |
5 ms |
512 KB |
011.txt |
AC |
5 ms |
512 KB |
012.txt |
AC |
5 ms |
512 KB |
013.txt |
AC |
5 ms |
512 KB |
014.txt |
AC |
5 ms |
512 KB |
015.txt |
AC |
49 ms |
512 KB |
016.txt |
AC |
8 ms |
512 KB |
017.txt |
AC |
17 ms |
512 KB |
018.txt |
AC |
8 ms |
512 KB |
019.txt |
AC |
19 ms |
512 KB |
020.txt |
AC |
9 ms |
512 KB |
021.txt |
AC |
42 ms |
512 KB |
022.txt |
AC |
9 ms |
512 KB |
023.txt |
AC |
13 ms |
512 KB |
024.txt |
AC |
43 ms |
512 KB |
025.txt |
AC |
11 ms |
512 KB |
026.txt |
AC |
27 ms |
512 KB |
027.txt |
AC |
40 ms |
512 KB |
028.txt |
AC |
18 ms |
512 KB |
029.txt |
AC |
22 ms |
512 KB |
030.txt |
AC |
40 ms |
512 KB |
031.txt |
AC |
44 ms |
512 KB |
032.txt |
AC |
8 ms |
512 KB |
033.txt |
AC |
5 ms |
512 KB |
034.txt |
AC |
19 ms |
512 KB |
035.txt |
AC |
25 ms |
512 KB |
036.txt |
AC |
8 ms |
512 KB |
037.txt |
AC |
5 ms |
512 KB |
038.txt |
AC |
60 ms |
512 KB |
039.txt |
AC |
5 ms |
512 KB |
040.txt |
AC |
5 ms |
512 KB |
041.txt |
AC |
14 ms |
512 KB |
042.txt |
AC |
5 ms |
512 KB |
043.txt |
AC |
5 ms |
512 KB |
044.txt |
AC |
5 ms |
512 KB |
045.txt |
AC |
5 ms |
512 KB |
046.txt |
AC |
5 ms |
512 KB |
047.txt |
AC |
5 ms |
512 KB |
048.txt |
AC |
5 ms |
512 KB |
049.txt |
AC |
5 ms |
512 KB |
example0.txt |
AC |
5 ms |
512 KB |
example1.txt |
AC |
6 ms |
512 KB |