結果

問題 No.412 花火大会
ユーザー ctyl_0ctyl_0
提出日時 2016-08-13 00:07:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,197 bytes
コンパイル時間 897 ms
コンパイル使用メモリ 99,032 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-07 12:38:21
合計ジャッジ時間 1,735 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

ll count(int n, int k){ // n個からk(>= 3)個以上任意にとる方法
    ll ans = 1LL << n;
    if (k >= 3){
        ans -= n * (n - 1) / 2;
    }
    if (k >= 2){
        ans -= n;
    }
    if (k >= 1){
        ans -= 1; // 0個
    }
    
    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    vector<int> B(3);
    rep(i, 3) cin >> B[i];
    sort(all(B));
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    sort(all(A));
    
    ll ret = 0;
    int i = 0, j = 0, k = 0;
    for(i = 0; i < N; i++){
        if(A[i] >= B[0]) break;
    }
    for(j = 0; j < N; j++){
        if(A[j] >= B[1]) break;
    }
    for(k = 0; k < N; k++){
        if(A[k] >= B[2]) break;
    }
//    cout << i << "," << j << "," << k << endl;
//    ll ans = 1LL << N;
//    if (N - k >= 3)
    ll a = i, b = j - i, c = k - j, d = N - k;
    
    if(d >= 3) {
        ll tmp = 1LL << d;
        tmp -= d * (d - 1) / 2;
        tmp -= d;
        tmp -= 1;
        ret += tmp * (1LL << (a + b + c));
    }
    if(d >= 2){
        ll tmp = d * (d - 1) / 2;
        tmp *= ((1LL << (b + c)) - 1);
        ret += tmp * (1LL << a);
    }
    if(d >= 1){
        ll tmp = 0;
        if (c >= 2){
            ll t = 1LL << c;
            t -= c;
            t -= 1;
            tmp += t * d * (1LL << (a + b));
        }
        if (c >= 1 && b >= 1){
            tmp += ((1LL << b) - 1) * c * d * (1LL << a);
        }
        ret += tmp;
    }
    
    output(ret, 0);
    
    
    return 0;
}
0