답안 #768962

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
768962 2023-06-29T03:01:36 Z anha3k25cvp Ice Hockey World Championship (CEOI15_bobek) C++14
100 / 100
818 ms 24928 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define dl double
#define st first
#define nd second
#define II pair <int, int>

using namespace std;

const int N = 5 + 1e5;
const int inf = 7 + 1e9;

struct fenwick {
    int n;
    vector <ll> tree;
    fenwick (int _n = 0) : n(_n) {
        tree.assign(n + 1, 0);
    }
    void update(int x) {
        for (int i = x; i <= n; i += i & -i)
            tree[i] ++;
    }
    ll get(int x) {
        ll ans = 0;
        for (int i = x; i > 0; i -= i & -i)
            ans += tree[i];
        return ans;
    }
};

int main() {
#define TASKNAME ""
    ios_base :: sync_with_stdio (0);
    cin.tie (0);
    if ( fopen( TASKNAME".inp", "r" ) ) {
        freopen (TASKNAME".inp", "r", stdin);
        freopen (TASKNAME".out", "w", stdout);
    }
    int n;
    ll m;
    cin >> n >> m;
    int n_ = n / 2;
    vector <ll> a(n_, 0), c;
    for (int i = 0; i < n_; i ++)
        cin >> a[i];
    for (int mask = 0; mask < (1 << n_); mask ++) {
        ll sum = 0;
        for (int si = mask; si > 0; si ^= si & -si) {
            int i = __builtin_ctz(si & -si);
            sum += a[i];
        }
        c.push_back(sum);
    }
    for (int mask = 0; mask < (1 << n_); mask ++) {
        ll sum = 0;
        for (int si = mask; si > 0; si ^= si & -si) {
            int i = __builtin_ctz(si & -si);
            sum += a[i];
        }
        c.push_back(sum);
    }
    sort(c.begin(), c.end());
    c.resize(unique(c.begin(), c.end()) - c.begin());
    fenwick f(c.size());
    for (int mask = 0; mask < (1 << n_); mask ++) {
        ll sum = 0;
        for (int si = mask; si > 0; si ^= si & -si) {
            int i = __builtin_ctz(si & -si);
            sum += a[i];
        }
        sum = lower_bound(c.begin(), c.end(), sum) - c.begin() + 1;
        f.update(sum);
    }
    n_ = n - n_;
    a.assign(n_, 0);
    for (int i = 0; i < n_; i ++)
        cin >> a[i];
    ll ans = 0;
    for (int mask = 0; mask < (1 << n_); mask ++) {
        ll sum = 0;
        for (int si = mask; si > 0; si ^= si & -si) {
            int i = __builtin_ctz(si & -si);
            sum += a[i];
        }
        sum = upper_bound(c.begin(), c.end(), m - sum) - c.begin();
        ans += f.get(sum);
    }
    cout << ans;
    return 0;
}

Compilation message

bobek.cpp: In function 'int main()':
bobek.cpp:37:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen (TASKNAME".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
bobek.cpp:38:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen (TASKNAME".out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 1 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 212 KB Output is correct
2 Correct 1 ms 324 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 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 1492 KB Output is correct
2 Correct 117 ms 5704 KB Output is correct
3 Correct 530 ms 20312 KB Output is correct
4 Correct 117 ms 5816 KB Output is correct
5 Correct 10 ms 1364 KB Output is correct
6 Correct 8 ms 896 KB Output is correct
7 Correct 20 ms 1872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 2512 KB Output is correct
2 Correct 33 ms 1744 KB Output is correct
3 Correct 161 ms 8608 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 4 ms 856 KB Output is correct
6 Correct 19 ms 1492 KB Output is correct
7 Correct 19 ms 1744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 3160 KB Output is correct
2 Correct 147 ms 5312 KB Output is correct
3 Correct 144 ms 5304 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 36 ms 4556 KB Output is correct
6 Correct 283 ms 16836 KB Output is correct
7 Correct 98 ms 6352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 405 ms 12620 KB Output is correct
2 Correct 32 ms 1872 KB Output is correct
3 Correct 13 ms 984 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 5 ms 856 KB Output is correct
6 Correct 226 ms 12624 KB Output is correct
7 Correct 22 ms 1872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 1872 KB Output is correct
2 Correct 129 ms 6352 KB Output is correct
3 Correct 13 ms 1088 KB Output is correct
4 Correct 12 ms 972 KB Output is correct
5 Correct 51 ms 4532 KB Output is correct
6 Correct 22 ms 1748 KB Output is correct
7 Correct 470 ms 24820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 724 ms 24928 KB Output is correct
2 Correct 35 ms 1872 KB Output is correct
3 Correct 12 ms 1088 KB Output is correct
4 Correct 818 ms 24876 KB Output is correct
5 Correct 70 ms 8648 KB Output is correct
6 Correct 22 ms 1856 KB Output is correct
7 Correct 47 ms 3320 KB Output is correct