Submission #281966

#TimeUsernameProblemLanguageResultExecution timeMemory
281966Atill83Detecting Molecules (IOI16_molecules)C++14
69 / 100
58 ms8040 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; #define ff first #define ss second typedef pair<int, int> pii; typedef long long ll; int n; int cnt = 0; vector<int> ans; map<pii, int> done; vector<ll> pre; int do_it(vector<pii> &vc, int idx, int l, int r, int k){ if(l <= 0 && r >= 0){ return 1; } int len = n - idx; int l1 = pre[idx + k - 1] - (idx != 0 ? pre[idx - 1] : 0), r1 = pre[n - 1] - (k == n ? 0 : pre[n - 1 - k]); int mxL = max(l1, l), mxR = min(r, r1); if(mxL <= mxR){ if(do_it(vc, idx + 1, l - vc[idx].ff, r - vc[idx].ff, k - 1)){ ans.push_back(vc[idx].ss); return 1; }else if(do_it(vc, idx + 1, l, r, k)){ return 1; }else{ assert(0); } }else{ return 0; } } vector<int> find_subset(int l, int u, vector<int> w) { ans.clear(); vector<pii> vc; ll top = 0; n = w.size(); for(int i: w) top += i; if(top < l) return ans; for(int i = 0; i < w.size(); i++){ vc.push_back({w[i], i}); } sort(vc.begin(), vc.end()); for(int i = 0; i < w.size(); i++){ pre.push_back(vc[i].ff); if(i) pre[i] += pre[i - 1]; } for(int i = 1; i <= n; i++){ if(do_it(vc, 0, l, u, i)) break; } return ans; }

Compilation message (stderr)

molecules.cpp: In function 'int do_it(std::vector<std::pair<int, int> >&, int, int, int, int)':
molecules.cpp:19:9: warning: unused variable 'len' [-Wunused-variable]
   19 |     int len = n - idx;
      |         ^~~
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:45:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i = 0; i < w.size(); i++){
      |                    ~~^~~~~~~~~~
molecules.cpp:50:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int i = 0; i < w.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...
#Verdict Execution timeMemoryGrader output
Fetching results...