Submission #977049

# Submission time Handle Problem Language Result Execution time Memory
977049 2024-05-07T10:48:07 Z SeenSiravit Ice Hockey World Championship (CEOI15_bobek) C++14
40 / 100
68 ms 8936 KB
#include<bits/stdc++.h>
#define ll long long

using namespace std;

const int mxN = 40 + 5 , mxM = 1e6 + 5;

int n;
ll m;
ll a[mxN];

void bruteforce(){
    // sub 1-4
    ll ans = 0;
    ll lim = 1<<n;


    for(int mask=0;mask<lim;mask++){
        ll sum = 0;

        for(int i=0;i<n;i++){
            if((1<<i) & mask) sum += a[i];
            if(sum > m) break;
        }

        if(sum <= m) ans++;
    }

    cout<< ans;
}

ll fw[mxM];

void update(int idx , int val){
    for(int i=idx;i<=m;i += (i & -i)) fw[i] += val;
}

int query(int idx){
    int cnt = 0;
    for(int i=idx;i>0;i -= (i & -i)) cnt += fw[i];
    return cnt;
}

void bruteforce2(){

    update(1 , 1);

    ll ans = 1;

    for(int i=0;i<n;i++){
        ll rm = m - a[i] + 1;

        int cnt = (rm<=0 ? 0 : query(rm));

        if(rm>0) update(a[i]+1 , 1);

        // cout<< i << " : " << cnt << "\n";
        ans += cnt;

        // for(int j=0;j<=m;j++) cout<< fw[j] << " ";
        // cout<< "\n";
    }

    cout<< ans;
}

int main(){
    ios::sync_with_stdio(0),cin.tie(0);

    cin>> n >> m;

    for(int i=0;i<n;i++) cin>> a[i];

    if(n<=20) bruteforce();
    else bruteforce2();


    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 452 KB Output is correct
2 Correct 4 ms 344 KB Output is correct
3 Correct 7 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
6 Correct 68 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 436 KB Output is correct
2 Correct 14 ms 344 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 60 ms 348 KB Output is correct
6 Correct 8 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 8936 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 8792 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 8792 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -