Submission #381491

#TimeUsernameProblemLanguageResultExecution timeMemory
381491IldarKASan (COCI17_san)C++14
96 / 120
355 ms65536 KiB
#include <bits/stdc++.h> using namespace std; struct node{ int bit[2]; int cnt; } t[4613881]; int n, h[41], g[41], sz = 1; long long k; vector < pair < int, long long > > v, v2; void add(long long x){ int v = 0; for(int j = 35; j >= 0; j--){ int c = ((x >> j) & 1); if(!t[v].bit[c]){ t[v].bit[c] = sz; sz++; } v = t[v].bit[c]; t[v].cnt++; } } void del(long long x){ int v = 0; for(int j = 35; j >= 0; j--){ int c = ((x >> j) & 1); v = t[v].bit[c]; t[v].cnt--; } } int get(long long x){ int v = 0; int ans = 0; for(int i = 35; i >= 0; i--){ int c = ((x >> i) & 1); if(!t[v].bit[c]){ t[v].bit[c] = sz; sz++; } if(c == 0 && t[v].bit[1]){ ans += t[t[v].bit[1]].cnt; } v = t[v].bit[c]; } ans += t[v].cnt; return ans; } int main(){ cin >> n >> k; for(int i = 1; i <= n; i++){ cin >> h[i] >> g[i]; } int q = n / 2; for(int i = 0; i < (1 << q); i++){ long long sum = 0; bool ok = 1; int last = 0; for(int j = 0; j < q; j++){ if((i >> j) & 1){ if(last > h[j + 1]){ ok = 0; break; } last = h[j + 1]; sum += g[j + 1]; } } if(ok){ v.push_back({last, sum}); } } sort(v.begin(), v.end()); int q2 = n - q; for(int i = 0; i < (1 << q2); i++){ long long sum = 0; bool ok = 1; int last = 0, first = 1e9 + 1; for(int j = 0; j < q2; j++){ if((i >> j) & 1){ if(first == (int)1e9 + 1){ first = h[j + 1 + q]; } if(last > h[j + 1 + q]){ ok = 0; break; } last = h[j + 1 + q]; sum += g[j + 1 + q]; } } if(ok){ add(sum); v2.push_back({first, sum}); } } sort(v2.begin(), v2.end()); int pos = 0; long long ans = 0; for(int i = 0; i < v.size(); i++){ while(pos < (int)v2.size() && v[i].first > v2[pos].first){ del(v2[pos].second); pos++; } ans += get(max(k - v[i].second, 0ll)); } cout << ans; }

Compilation message (stderr)

san.cpp: In function 'int main()':
san.cpp:99:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |     for(int i = 0; i < v.size(); i++){
      |                    ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...