# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
886723 |
2023-12-12T17:48:50 Z |
vjudge1 |
San (COCI17_san) |
C++17 |
|
182 ms |
6592 KB |
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define ONLINE_JUDGE
void solve() {
int n;
i64 k;
cin >> n >> k;
vector <int> h(n), g(n);
for(int i = 0; i < n; i++) {
cin >> h[i] >> g[i];
}
vector <i64> idxs[n + 2];
int half = n / 2;
i64 ans = 0;
for(int mask = 1; mask < (1 << half); mask++) {
int last = 0, lst = -1;
i64 sum = 0;
bool ok = true;
for(int i = 0; i < half; i++) {
if(mask & (1 << i)) {
if(h[i] < last) {
ok = false;
break;
}
last = h[i];
sum += g[i];
lst = i;
}
}
if(ok) {
idxs[lst].emplace_back(sum);
ans += (sum >= k);
}
}
for(int mask = 1; mask < (1 << (n - half)); mask++) {
int last = 0, fir = -1;
i64 sum = 0;
bool ok = true;
for(int i = 0; i < (n - half); i++) {
if(mask & (1 << i)) {
if(h[i + half] < last) {
ok = false;
break;
}
last = h[i + half];
sum += g[i + half];
if(fir == -1) {
fir = half + i;
}
}
}
if(ok) {
idxs[fir].emplace_back(sum);
ans += (sum >= k);
}
}
for(int i = 0; i < n; i++) {
sort(idxs[i].begin(), idxs[i].end());
/*
cerr << i << ": ";
for(int &j : idxs[i]) {
cerr << j << " ";
}
cerr << "\n";
*/
}
for(int i = 0; i < half; i++) {
for(i64 &j : idxs[i]) {
for(int l = half; l < n; l++) {
if(h[i] < h[l]) {
auto it = lower_bound(idxs[l].begin(), idxs[l].end(), k - j);
ans += idxs[l].end() - it;
}
}
}
}
cout << ans;
return;
}
signed main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int t = 1; //cin >> t;
for(int i = 1; i <= t; i++) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
1020 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
1872 KB |
Output is correct |
2 |
Correct |
15 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
182 ms |
6592 KB |
Output is correct |
2 |
Correct |
94 ms |
1812 KB |
Output is correct |