Submission #875773

#TimeUsernameProblemLanguageResultExecution timeMemory
875773raul2008487Detecting Molecules (IOI16_molecules)C++17
19 / 100
1 ms392 KiB
#include<bits/stdc++.h> #include "molecules.h" #define ll int #define all(v) v.begin(), v.end() #define pb push_back #define fi first #define se second #define vl vector<ll> using namespace std; bool check(ll cur, ll low, ll high){ return (cur <= high && cur >= low); } vector<int> find_subset(int l, int u, vector<int> w) { vector<int> ans; vector<pair<int,int>> p; ll i, j, n = w.size(), left = 0, right = 1; long long sum = w[0]; for(i=0;i<n;i++){ p.pb({w[i], i}); } sort(all(p)); bool flag = 0; while(left <= right){ if(check(sum, l, u)){ break; } else if(sum > u){ if(left == (n-1)){ flag = 1; break; } sum -= p[left].fi; left++; } else if(sum < l){ if(right == n){ flag = 1; break; } sum += p[right].fi; right++; } } if(flag){ return ans; } else{ for(i=left;i<right;i++){ ans.pb(p[i].se); } return ans; } }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:16:11: warning: unused variable 'j' [-Wunused-variable]
   16 |     ll i, j, n = w.size(), left = 0, right = 1;
      |           ^
#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...