Submission #81039

# Submission time Handle Problem Language Result Execution time Memory
81039 2018-10-23T15:13:29 Z ngot23 San (COCI17_san) C++11
24 / 120
345 ms 1752 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, ans=0;;

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

//#define TEST

int main() {
    #ifdef TEST
        freopen(".inp", "w", stdout);
        srand(time(NULL));
        int xx=rand()%10+1;
        cout << xx << ' ' << rand()%15+1 << '\n';
        rep(i, 1, xx) {
            cout << rand()%10+1 << ' ';
            cout << rand()%10+1 << '\n';
        }

    #else
    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;
    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);
        if(xx>=k) ++ans;
    }

    rep(i, 1, num) sort(v[i].begin(), v[i].end());

    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;
    #endif // TEST
    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 464 KB Output is correct
2 Correct 2 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 71 ms 712 KB Output is correct
2 Incorrect 67 ms 712 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 345 ms 1752 KB Output isn't correct
2 Halted 0 ms 0 KB -