# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
34853 | 2017-11-16T08:08:22 Z | szawinis | San (COCI17_san) | C++14 | 239 ms | 4800 KB |
#include <bits/stdc++.h> using namespace std; using ll = long long; int n, h[42], g[42]; ll k, ans; vector<ll> f[22]; int main() { cin >> n >> k; for(int i = 1; i <= n; i++) cin >> h[i] >> g[i]; h[0] = INT_MIN; h[n+1] = INT_MAX; for(int mask = 0; mask < 1 << n/2; mask++) { int pre = 0; ll sum = 0; bool valid = true; for(int i = 1; i <= n/2; i++) if(mask >> i-1 & 1) { sum += g[i]; valid &= !pre || h[i] >= h[pre]; pre = i; } if(valid) f[pre].push_back(sum); } for(int i = 0; i <= n/2; i++) sort(f[i].begin(), f[i].end()); for(int mask = 0; mask < 1 << (n+1)/2; mask++) { int pre = n+1; ll sum = 0; bool valid = true; for(int i = n; i >= n/2+1; i--) if(mask >> i-n/2-1 & 1) { sum += g[i]; valid &= pre == n+1 || h[i] <= h[pre]; pre = i; } if(valid) for(int i = 0; i <= n/2; i++) if(h[i] <= h[pre]) { auto it = lower_bound(f[i].begin(), f[i].end(), k - sum); ans += f[i].end() - it; } } cout << ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2016 KB | Output is correct |
2 | Correct | 0 ms | 2016 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2016 KB | Output is correct |
2 | Correct | 0 ms | 2016 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 2348 KB | Output is correct |
2 | Correct | 13 ms | 2016 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 59 ms | 3028 KB | Output is correct |
2 | Correct | 49 ms | 2160 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 239 ms | 4800 KB | Output is correct |
2 | Correct | 173 ms | 3944 KB | Output is correct |