結果
問題 | No.412 花火大会 |
ユーザー | tottoripaper |
提出日時 | 2016-10-19 16:16:51 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,356 bytes |
コンパイル時間 | 1,749 ms |
コンパイル使用メモリ | 149,136 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-08-14 17:37:58 |
合計ジャッジ時間 | 2,976 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,384 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,376 KB |
testcase_09 | AC | 1 ms
4,384 KB |
testcase_10 | AC | 2 ms
4,380 KB |
testcase_11 | AC | 2 ms
4,380 KB |
testcase_12 | AC | 2 ms
4,380 KB |
testcase_13 | AC | 1 ms
4,376 KB |
testcase_14 | AC | 2 ms
4,380 KB |
testcase_15 | AC | 2 ms
4,384 KB |
testcase_16 | AC | 2 ms
4,380 KB |
testcase_17 | AC | 1 ms
4,380 KB |
testcase_18 | AC | 2 ms
4,380 KB |
testcase_19 | AC | 1 ms
4,380 KB |
testcase_20 | AC | 2 ms
4,380 KB |
testcase_21 | AC | 2 ms
4,376 KB |
ソースコード
#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; }