답안 #886709

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
886709 2023-12-12T17:25:43 Z vjudge1 San (COCI17_san) C++17
96 / 120
340 ms 20844 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<n1;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();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 2648 KB Output is correct
2 Correct 3 ms 1260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 10584 KB Output is correct
2 Correct 20 ms 2904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 340 ms 20844 KB Output is correct
2 Incorrect 94 ms 10840 KB Output isn't correct
3 Halted 0 ms 0 KB -