Submission #381523

#TimeUsernameProblemLanguageResultExecution timeMemory
381523IldarKASan (COCI17_san)C++14
120 / 120
479 ms37428 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Общий файл. #include <ext/pb_ds/tree_policy.hpp> // Содержит класс tree_order_statistics_node_update using namespace std; using namespace __gnu_pbds; typedef tree< pair < long long, int >, null_type, less<pair < long long, int >>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; ordered_set s; int n, h[41], g[41]; long long k; vector < pair < int, long long > > v; vector < pair < int, pair < long long, int > > > v2; int main(){ cin >> n >> k; for(int i = 1; i <= n; i++){ cin >> h[i] >> g[i]; } int q = (n + 1) / 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){ s.insert({sum, i}); v2.push_back({first, {sum, i}}); } } 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){ s.erase(v2[pos].second); pos++; } ans += ((int)s.size() - (int)s.order_of_key({max(k - v[i].second, 0ll), 0})); } cout << ans; }

Compilation message (stderr)

san.cpp: In function 'int main()':
san.cpp:63: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]
   63 |     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...