Submission #1021893

#TimeUsernameProblemLanguageResultExecution timeMemory
1021893parsadox2Detecting Molecules (IOI16_molecules)C++17
100 / 100
50 ms6808 KiB
#include "molecules.h" #include <bits/stdc++.h> #define F first #define S second using namespace std; const int N = 2e5 + 10; long long prf[N] , suf[N]; vector<int> find_subset(int l, int r, std::vector<int> w) { vector <int> vec; int n = w.size(); vector <pair<int , int>> all; for(int i = 0 ; i < n ; i++) all.push_back(make_pair(w[i] , i)); sort(all.begin() , all.end()); prf[0] = all[0].F; for(int i = 1 ; i < n ; i++) prf[i] = prf[i - 1] + all[i].F; for(int i = n - 1 ; i >= 0 ; i--) suf[i] = suf[i + 1] + all[i].F; for(int i = 0 ; i < n ; i++) { if(prf[i] > r || suf[n - 1 - i] < l) continue; long long sum = prf[i]; for(int j = 0 ; j <= i ; j++) vec.push_back(all[j].S); int las = n - 1; for(int j = i ; j >= 0 ; j--) { if(sum >= l) break; sum -= all[j].F; vec[j] = all[las].S; sum += all[las].F; las--; } break; } return vec; }
#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...