Submission #524749

#TimeUsernameProblemLanguageResultExecution timeMemory
524749vijayDetecting Molecules (IOI16_molecules)C++98
46 / 100
3 ms460 KiB
#include <iostream> #include <vector> #include <algorithm> #include <fstream> #include <bitset> using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef vector<int> vi; #define trav(a, x) for (auto& a: x) #define all(x) begin(x), end(x) #define mp make_pair #define pb push_back #define f first #define s second #define NUM(a) (sizeof(a)/sizeof(*a)) vector<int> find_subset(int l, int u, vector<int> w){ vector<int> result; int n = w.size(); vector<pair<int, int> > a(n, pair<int, int>()); for(int i = 0; i < n; i++){ a[i] = mp(w[i], i); } sort(a.begin(), a.end()); int right = 0; int sum = 0; for(int left = 0; left < n; left++){ while(sum < l && sum < l){ sum += a[right].f; right++; } if(sum >= l && sum <= u){ vector<int> result; for(int i = left; i < right; i++){ result.pb(a[i].s); } return result; } sum -= a[left].f; } // // for(int i = 0; i < n; i++){ // cout << a[i].f << " " << a[i].s << "\n"; // } // vector<int> minSum(n + 1, 0); // vector<int> maxSum(n + 1, 0); // for(int k = 1; k <= n; k++){ // minSum[k] = minSum[k - 1] + a[k - 1].f; // maxSum[k] = maxSum[k - 1] + a[n - k].f; // } // // for(int k = 1; k <= n; k++){ // if(minSum[k] <= u && maxSum[k] >= l){ // // this could fit within the range! // // System.out.println("this could fit within the range! " + k); // int currSum = minSum[k]; // int idx = k; // while(idx <= n){ // if(currSum >= l && currSum <= u){ // // System.out.println(k); // for(int i = idx - k; i < idx; i++){ // result.pb(a[i].s); // } // return result; // } // // if(idx == n){ // break; // } // // currSum += a[idx].f; // currSum -= a[idx - k].f; // idx++; // } // } // } result.resize(0); return result; } // int main(){ // ios_base::sync_with_stdio(0); // cin.tie(0); // // vector<int> tc; // tc.pb(6);tc.pb(8);tc.pb(8);tc.pb(7); // vector<int> v = find_subset(15, 17, tc); // for(auto& a: v){ // cout << a << "\n"; // } // }
#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...