Submission #250512

# Submission time Handle Problem Language Result Execution time Memory
250512 2020-07-18T08:44:27 Z Vladikus004 San (COCI17_san) C++14
0 / 120
339 ms 10748 KB
#include <bits/stdc++.h>
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int N = 41;
int n, h[N], g[N];
ll k;
vector <ll> v1[21], v2[21];

bool can(int mask){
    int mx = -inf;
    for (int i = 0; i < n; i++){
        if (!(mask & (1<<i))) continue;
        if (mx > h[i]) return false;
        mx = h[i];
    }
    return true;
}

ll get_sum(int mask){
    ll sum = 0;
    for (int i = 0; i < n; i++){
        if (!(mask & (1<<i))) continue;
        sum += g[i];
    }
    return sum;
}

int f(int x, int sz){
    int cnt = 0;
    for (int i = sz - 1; i >= 0; i--){
        if ((1<<i)&x) return cnt;
        cnt++;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif // LOCAL
//    cout << __builtin_ctz(4) << "\n";
    cin >> n >> k;
    for (int i = 0; i < n; i++){
        cin >> h[i] >> g[i];
    }
    if (n & 1){
        h[n] = inf;
        ++n;
    }
    int ans = 0;
    int sz = n / 2;
    for (int mask = 1; mask < (1<<sz); mask++){
        if (can(mask)){
            ll sum = get_sum(mask);
            v1[f(mask, sz)].push_back(sum);
            if (sum >= k)
            ans += 1;
        }
    }
    for (int mask = 1; mask < (1<<sz); mask++){
        int cmask = mask<<sz;
        if (can(cmask)){
            ll sum = get_sum(cmask);
            v2[__builtin_ctz(cmask) - sz].push_back(sum);
            if (sum >= k)
            ans += 1;
        }
    }
    for (int i = 0; i < sz; i++){
        for (int g = 0; g < sz; g++){
            if (h[sz - 1 - i] > h[g + sz]) continue;
            for (int j = 0; j < v1[i].size(); j++){
//                cout << i << " : " << v1[i][j] << "\n";
                ans += v2[g].size()-(lower_bound(all(v2[g]), k - v1[i][j])-v2[g].begin());
            }
        }
    }
    cout << ans;
}

Compilation message

san.cpp: In function 'int main()':
san.cpp:79:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j = 0; j < v1[i].size(); j++){
                             ~~^~~~~~~~~~~~~~
san.cpp: In function 'int f(int, int)':
san.cpp:39:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 1404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 50 ms 1808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 339 ms 10748 KB Output isn't correct
2 Halted 0 ms 0 KB -