제출 #298006

#제출 시각아이디문제언어결과실행 시간메모리
298006AzimjonDetecting Molecules (IOI16_molecules)C++17
100 / 100
62 ms5496 KiB
// name = molecules_sk_greedy_1_n.cpp, type = cpp.g++11 #include "molecules.h" /** Author: Sergey Kopeliovich ([email protected]) */ // idea : answer is a segment of sorted weights // time = O(n) #include <cstdio> #include <algorithm> #include <vector> using namespace std; #define forn(i, n) for (int i = 0; i < (int)(n); i++) typedef pair <int, int> pii; typedef long long ll; // return value: result if solution exists and empty vector otherwise vector<int> find_subset( int L, int U, vector<int> w ) { int n = w.size(); vector<pii> wp(n); forn(i, n) wp[i] = pii(w[i], i); sort(wp.begin(), wp.end()); int r = 0; ll sum = 0; forn(l, n) { while (r < n && sum < L) sum += wp[r++].first; if (L <= sum && sum <= U) { vector<int> res; for (; l < r; l++) res.push_back(wp[l].second); return res; } sum -= wp[l].first; } return vector<int>(); }
#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...