Submission #381499

# Submission time Handle Problem Language Result Execution time Memory
381499 2021-03-25T08:38:38 Z IldarKA Usmjeri (COCI17_usmjeri) C++14
0 / 140
2000 ms 66248 KB
#include <bits/stdc++.h>

using namespace std;
struct node{
    int bit[2];
    int cnt;
} t[4613899];
int n, h[41], g[41], sz = 1;
long long k;
vector < pair < int, long long > > v, v2;
void add(long long x){
    int v = 0;
    for(int j = 35; j >= 0; j--){
        int c = ((x >> j) & 1);
        if(!t[v].bit[c]){
            t[v].bit[c] = sz;
            sz++;
        }
        v = t[v].bit[c];
        t[v].cnt++;
    }
}
void del(long long x){
    int v = 0;
    for(int j = 35; j >= 0; j--){
        int c = ((x >> j) & 1);
        v = t[v].bit[c];
        t[v].cnt--;
    }
}
int get(long long x){
    int v = 0;
    int ans = 0;
    for(int i = 35; i >= 0; i--){
        int c = ((x >> i) & 1);
        if(!t[v].bit[c]){
            t[v].bit[c] = sz;
            sz++;
        }
        if(c == 0 && t[v].bit[1]){
            ans += t[t[v].bit[1]].cnt;
        }
        v = t[v].bit[c];
    }
    ans += t[v].cnt;
    return ans;
}
int main(){
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> h[i] >> g[i];
    }
    int q = (n + 1) / 2;
    if(n == 40){
        q = 21;
    }
    for(int i = 0; i < (1 << q); i++){
        long long sum = 0;
        bool ok = 1;
        int last = 0;
        for(int j = 0; j < q; j++){
            if((i >> j) & 1){
                if(last > h[j + 1]){
                    ok = 0;
                    break;
                }
                last = h[j + 1];
                sum += g[j + 1];
            }
        }
        if(ok){
            v.push_back({last, sum});
        }
    }
    sort(v.begin(), v.end());
    int q2 = n - q;
    for(int i = 0; i < (1 << q2); i++){
        long long sum = 0;
        bool ok = 1;
        int last = 0, first = 1e9 + 1;
        for(int j = 0; j < q2; j++){
            if((i >> j) & 1){
                if(first == (int)1e9 + 1){
                    first = h[j + 1 + q];
                }
                if(last > h[j + 1 + q]){
                    ok = 0;
                    break;
                }
                last = h[j + 1 + q];
                sum += g[j + 1 + q];
            }
        }
        if(ok){
            add(sum);
            v2.push_back({first, sum});
        }
    }
    sort(v2.begin(), v2.end());
    int pos = 0;
    long long ans = 0;
    for(int i = 0; i < v.size(); i++){
        while(pos < (int)v2.size() && v[i].first > v2[pos].first){
            del(v2[pos].second);
            pos++;
        }
        ans += get(max(k - v[i].second, 0ll));
    }
    cout << ans;
}

Compilation message

usmjeri.cpp: In function 'int main()':
usmjeri.cpp:102:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |     for(int i = 0; i < v.size(); i++){
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 873 ms 66240 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 846 ms 66248 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2085 ms 400 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2100 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 157 ms 4844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 167 ms 5192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 154 ms 4844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 169 ms 4844 KB Output isn't correct
2 Halted 0 ms 0 KB -