Submission #886707

# Submission time Handle Problem Language Result Execution time Memory
886707 2023-12-12T17:23:17 Z vjudge1 San (COCI17_san) C++17
48 / 120
370 ms 20968 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++;
      }
      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 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 55 ms 10764 KB Output is correct
2 Incorrect 23 ms 2924 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 370 ms 20968 KB Output isn't correct
2 Halted 0 ms 0 KB -