Submission #1007964

#TimeUsernameProblemLanguageResultExecution timeMemory
1007964ProtonDecay314Detecting Molecules (IOI16_molecules)C++17
100 / 100
44 ms10688 KiB
/* 5, 5, 6, 6 0, 0, 1, 1 1, 1, 2, 2 15, 10, 5, -1, -7 1, 2, 2, 1, 1 [14, 15] [8, 10], [3, 5], [-2, -1], [-8, -7] 15, 17 [6, 8, 8, 7] 2, 2, 1, 0 17, 11, 4, -4, -12 2, 4, 4, 3, 2 ?, 8, 8, 7, 6 [4, 0] [15, 17] [7, 11], [0, 4], [-7, -4], [-14, -12], [0, 1] [6, 8] [13, 14] 0, 2, 2, 1, 0 [0, 2], [6, 10], [13, 17], [21, 25], [29, 31] 23, 24, 25 10, 20 20, --- [6, 9, 9] [15, 18] 0, 3, 3, 0 [0, 3], [6, 12], [15, 21], [24, 27] --- 4 12 14 5 5 5 7 0 2 5 9 10 12 15 17 22 24 0 2 5 7 10 12 15 17 22 24 */ #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<int> vi; #define fi first #define se second vi find_subset(int l, int u, vi wint) { ll n = wint.size(); vpll w; for(ll i = 0; i < n; i++) { w.push_back({wint[i], i}); } sort(w.begin(), w.end()); vll lb(n + 1, 0ll); vll ub(n + 1, 0ll); for(ll i = 0; i < n; i++) { lb[i + 1] = lb[i] + w[i].fi; ub[i + 1] = ub[i] + w[n - i - 1].fi; } for(ll i = 0; i < n + 1; i++) { ub[i] = ub[i] + u - l; #ifdef DEBUG cout << ub[i] << endl; #endif } // ub[n] = lb[n] + u - l; ll cur_int_ind = 0ll; while(cur_int_ind < n + 1 && !(lb[cur_int_ind] <= u && u <= ub[cur_int_ind])) { cur_int_ind++; } // No interval found #ifdef DEBUG cout << "INTERVAL: " << cur_int_ind << endl; #endif if(cur_int_ind == n + 1) return {}; ll p2 = n - 1; vi inds; ll cur_sum = u; while(cur_int_ind > 0 && p2 >= 0) { while(p2 >= 0 && cur_sum - w[p2].fi < lb[cur_int_ind - 1]) p2--; cur_sum -= w[p2].fi; cur_int_ind--; inds.push_back(w[p2].se); p2--; } // #ifdef DEBUG // return vector<int>(vals.begin(), vals.end()); // #endif return inds; } // Driver function #ifdef DEBUG int main() { ll n, l, u; cin >> n >> l >> u; vi w(n, 0ll); for(int& wv : w) { cin >> wv; } vi ans = find_subset(l, u, w); for(int i : ans) { cout << i << " "; } cout << endl; return 0; } #endif
#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...