結果
問題 | No.412 花火大会 |
ユーザー |
![]() |
提出日時 | 2016-10-19 16:16:51 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,356 bytes |
コンパイル時間 | 1,320 ms |
コンパイル使用メモリ | 162,276 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-22 16:42:18 |
合計ジャッジ時間 | 2,216 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define fst(t) std::get<0>(t) #define snd(t) std::get<1>(t) #define thd(t) std::get<2>(t) using ll = long long; using P = std::tuple<int,int>; const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1}; int Bs[3], Cs[3], Ds[3], Es[3]; int N, M, E[30]; template <typename T> T expt(T a, T n, T mod = std::numeric_limits<T>::max()){ T res = 1; while(n){ if(n & 1){res = res * a % mod;} a = a * a % mod; n >>= 1; } return res; } // nCk template <typename T> T nCk(T n, T k){ if(n < k){return 0;} T res = 1; for(T i=n;i>n-k;--i){res *= i;} for(T i=1;i<=k;++i){res /= i;} return res; } ll calc(int i, int rest, int redu){ int cn = (i > 0 ? Ds[i-1] : N) - Ds[i]; ll res = 0ll; // j >= rest if(rest <= cn){ ll x = 1ll << cn; for(int j=0;j<rest;++j){ x -= nCk(1ll * cn, 1ll * j); } // std::cout << "X: " << x << std::endl; x = x << Ds[i]; res += x; } // 2^7 = 128 // 7C0 = 1, 7C1 = 7, 7C2 = 21 // 99 // 8 // j = rest - 1, j = rest - 2, ..., j = 1 for(int j=0;j<rest;++j){ if(j < Es[i] - redu){continue;} if(cn < j){break;} ll x = nCk(1ll * cn, 1ll * j) * calc(i+1, rest-j, redu - (Es[i] - j)); // std::cout << "called by " << "(" << i << ", " << rest << ", " << redu << "): " << j << ", " << x << std::endl; res += x; } // std::cout << "calc " << i << ", " << rest << ", " << redu << ": " << res << std::endl; return res; } int main(){ //* std::cin.tie(nullptr); std::ios::sync_with_stdio(false); /*/ /*/ for(int i=0;i<3;++i){ std::cin >> Bs[i]; } sort(Bs, Bs+3, std::greater<int>()); std::cin >> N; for(int i=0;i<N;++i){ std::cin >> E[i]; } sort(E, E+N); for(int i=0;i<3;++i){ Cs[i] = lower_bound(E, E+N, Bs[i]) - E; } ll res = 0; if(Cs[0] < N && Cs[1] < N && Cs[2] < N){ M = 0; for(int i=0,j=0;i<3;i=j,++M){ while(j < 3 && Cs[j] == Cs[i]){++j;} Ds[M] = Cs[i]; Es[M] = j - i; } res = calc(0, 3, 0); } std::cout << res << std::endl; }