Submission #81038

# Submission time Handle Problem Language Result Execution time Memory
81038 2018-10-23T15:03:38 Z ngot23 San (COCI17_san) C++11
24 / 120
322 ms 3276 KB
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i=(a) ; i<=(b) ; ++i)
#define Task ""
using namespace std;
const int N=45;
vector <int > v[25];
int n, h[N], g[N], b[25], cnt;
long long k;

int get(int xx, int i) {
    return (xx>>i)&1;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen(Task".inp", "r", stdin);
    //freopen(Task".out", "w", stdout);
    cin >> n >> k;
    rep(i, 1, n) cin >> h[i] >> g[i];
    int num=(n+1)/2;
    rep(i, 0, (1ll<<num)-1) {
        cnt=0;
        rep(j, 1, num) {
            if(get(i, j-1)) b[++cnt]=j;
        }
        bool ok=0;
        rep(j, 2, cnt) {
            if(h[b[j]]<h[b[j-1]]) { ok=1; break; }
        }
        if(ok) continue;
        long long xx=0;
        rep(j, 1, cnt) {
            xx+=g[b[j]];
        }
        v[b[cnt]].push_back(xx);
    }
    long long ans=0;
    rep(i, 1, num) {
        sort(v[i].begin(), v[i].end());
        if(v[i].back()<k) continue;
        int id=lower_bound(v[i].begin(), v[i].end(), k)-v[i].begin();
        ans+=v[i].size()-id;
    }
    int num2=n-num;
    rep(i, 1, (1ll<<num2)-1) {
        cnt=0;
        rep(j, 1, num2) {
            if(get(i, j-1)) b[++cnt]=j+num;
        }
        bool ok=0;
        rep(j, 2, cnt) {
            if(h[b[j]]<h[b[j-1]]) { ok=1; break; }
        }
        if(ok) continue;
        long long xx=0;
        rep(j, 1, cnt) xx+=g[b[j]];
        if(xx>=k) ++ans;
        rep(j, 1, num) {
            if((h[j]>h[b[1]])||(v[j].back()<k-xx)) continue;
            int id=lower_bound(v[j].begin(), v[j].end(), k-xx)-v[j].begin();
            ans+=v[j].size()-id;
        }
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 508 KB Output is correct
2 Correct 2 ms 556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 69 ms 888 KB Output is correct
2 Incorrect 68 ms 888 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 322 ms 3276 KB Output isn't correct
2 Halted 0 ms 0 KB -