# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
886705 |
2023-12-12T17:21:26 Z |
vjudge1 |
San (COCI17_san) |
C++17 |
|
693 ms |
25820 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sp << " " <<
#define int long long
#define vi vector<int>
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
#define pii pair<int,int>
#define pb push_back
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int N = 5e5+1;
const int inf = 1e9+1;
void solve() {
int n,k;
cin >> n >> k;
vi h(n+1),g(n+1);
F(i,n) cin >> h[i] >> g[i];
int n1 = n-n/2,n2 = n/2;
int lim = (1<<n2);
vi sm(lim);
ordered_set ss[n2+1];
int ans = 0;
for (int i=0;i<lim;i++) {
int smm = 0;
int prev = 0,first=0;
bool cool = 1;
for (int j=0;j<n2;j++) {
if (i&(1<<j)) {
if (h[n1+j+1] < prev) {
cool = 0;
break;
}
if (!first) first = j+1;
prev = h[n1+j+1];
smm+=g[n1+j+1];
}
}
if (cool) {
if (smm >= k) {
ans++;
cout << i sp smm << endl;
}
ss[first].insert(smm);
}
}
lim = (1<<n1);
for (int i=1;i<lim;i++) {
int smm = 0,prev = 0;
bool cool = 1;
for (int j=0;j<n2;j++) {
if (i&(1<<j)) {
if (h[j+1] < prev) {
cool = 0;
break;
}
prev = h[j+1];
smm+=g[j+1];
}
}
if (!cool) continue;
if (smm >= k) {
ans++;
}
for (int j=1;j<=n2;j++) {
if (h[n1+j] >= prev) ans+=ss[j].size()-ss[j].order_of_key(k-smm);
}
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
int t = 1;
//cin >> t;
F(i,t) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
63 ms |
3056 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
216 ms |
12704 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
693 ms |
25820 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |