답안 #555445

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
555445 2022-04-30T23:41:10 Z hidden1 Ice Hockey World Championship (CEOI15_bobek) C++14
100 / 100
524 ms 17000 KB
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define endl "\n"

#define out(x) "[" << #x << "=" << x << "]"
struct debug {
    debug() { cerr << "DEBUGGER: " << endl; }
    ~debug() { cerr << endl << "DEBUGGER_END " << endl; }

    template<class T>
    debug& operator <<(const T x) {
        cerr << x << " ";
        return *this;
    }
};

template<class T> inline ostream &operator <<(ostream &out, const vector<T> &x) {
    for(const auto &it : x) {
        out << it << " ";
    }
    return out;
}
template<class T, class T2> inline ostream &operator <<(ostream &out, const pair<T, T2> &x) {
    return out << x.first << " " << x.second;
}
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }

typedef long long ll;
const ll mod = 1e9 + 7;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

const ll MAX_N = 1e5 + 10;
vector<ll> st;
ll n;
ll m;
ll arr[MAX_N];

void solveLeft(ll l, ll r) {
    for(ll mask = 0; mask < (1 << (r - l + 1)); mask ++) {
        ll sum = 0;
        for(ll j = l; j <= r; j ++) {
            if(mask & (1 << (j - l))) {
                sum += arr[j];
            }
        }
        st.push_back(sum);
    }
    sort(st.begin(), st.end());

    for(auto it : st) {
        cerr << it << " ";
    }
    cerr << endl;
}

ll ret = 0;

void solveRght(ll l, ll r) {
    for(ll mask = 0; mask < (1 << (r - l + 1)); mask ++) {
        ll sum = 0;
        for(ll j = l; j <= r; j ++) {
            if(mask & (1 << (j - l))) {
                sum += arr[j];
            }
        }

        cerr << "Adding " << sum << " " << (lower_bound(st.begin(), st.end(), m - sum + 1) - st.begin()) << endl;

        ret += (lower_bound(st.begin(), st.end(), m - sum + 1) - st.begin());
    }
}

signed main() {
#ifndef LOCAL
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#endif

    cin >> n >> m;
    for(int i = 0; i < n; i ++) {
        cin >> arr[i];
    }

    solveLeft(0, n / 2);
    solveRght(n / 2 + 1, n - 1);

    cout << ret << endl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 1492 KB Output is correct
2 Correct 104 ms 4556 KB Output is correct
3 Correct 524 ms 16788 KB Output is correct
4 Correct 104 ms 4560 KB Output is correct
5 Correct 16 ms 1492 KB Output is correct
6 Correct 9 ms 972 KB Output is correct
7 Correct 20 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 2468 KB Output is correct
2 Correct 29 ms 1444 KB Output is correct
3 Correct 191 ms 8640 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 8 ms 984 KB Output is correct
6 Correct 20 ms 1492 KB Output is correct
7 Correct 19 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 2504 KB Output is correct
2 Correct 130 ms 4548 KB Output is correct
3 Correct 131 ms 4528 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 77 ms 4552 KB Output is correct
6 Correct 291 ms 16876 KB Output is correct
7 Correct 89 ms 4564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 285 ms 8664 KB Output is correct
2 Correct 26 ms 1480 KB Output is correct
3 Correct 11 ms 984 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 10 ms 984 KB Output is correct
6 Correct 196 ms 8668 KB Output is correct
7 Correct 18 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 1480 KB Output is correct
2 Correct 97 ms 4568 KB Output is correct
3 Correct 10 ms 972 KB Output is correct
4 Correct 11 ms 984 KB Output is correct
5 Correct 93 ms 4556 KB Output is correct
6 Correct 22 ms 1492 KB Output is correct
7 Correct 335 ms 16812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 411 ms 16936 KB Output is correct
2 Correct 30 ms 1480 KB Output is correct
3 Correct 11 ms 984 KB Output is correct
4 Correct 506 ms 17000 KB Output is correct
5 Correct 134 ms 8568 KB Output is correct
6 Correct 18 ms 1492 KB Output is correct
7 Correct 39 ms 2436 KB Output is correct