답안 #768960

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
768960 2023-06-29T03:00:13 Z anha3k25cvp Ice Hockey World Championship (CEOI15_bobek) C++14
50 / 100
511 ms 11988 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 <int> 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 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 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 320 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 984 KB Output is correct
2 Correct 119 ms 3780 KB Output is correct
3 Correct 511 ms 11988 KB Output is correct
4 Correct 117 ms 3776 KB Output is correct
5 Correct 10 ms 984 KB Output is correct
6 Correct 8 ms 600 KB Output is correct
7 Correct 20 ms 1452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 1480 KB Output is correct
2 Correct 33 ms 1364 KB Output is correct
3 Correct 165 ms 4568 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 4 ms 600 KB Output is correct
6 Correct 19 ms 968 KB Output is correct
7 Correct 20 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 2264 KB Output is correct
2 Correct 145 ms 3268 KB Output is correct
3 Correct 142 ms 3268 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 41 ms 2512 KB Output is correct
6 Correct 285 ms 8656 KB Output is correct
7 Correct 96 ms 4548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 51 ms 4564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 94 ms 8648 KB Output isn't correct
2 Halted 0 ms 0 KB -