Submission #1114466

#TimeUsernameProblemLanguageResultExecution timeMemory
1114466HostekDetecting Molecules (IOI16_molecules)C++17
69 / 100
41 ms6596 KiB
// https://oj.uz/problem/view/IOI16_molecules // https://ioinformatics.org/files/ioi2016problem1.pdf // #define GARY_DBG #ifndef GARY_DBG #include "molecules.h" #endif #include <bits/stdc++.h> // #define int long long constexpr int sizik = 1000 * 1001; #define ar std::array #define pr std::pair #define vec std::vector typedef vec<vec<int>> _kra; std::vector<int32_t> find_subset(int l, int u, std::vector<int32_t> w) { int n = (int)w.size(); std::vector<ar<int, 2>> local_w; for (int i = 0; i < n; i++) { local_w.push_back({w[i], i}); } std::sort(local_w.begin(), local_w.end()); std::deque<int> ans; int p = 0, k = -1, sum = 0; while (k < n) { if (l <= sum && sum <= u) { // conv ans to vector; std::vector<int32_t> rans; for (const auto& a : ans) { rans.push_back(a); } std::sort(rans.begin(), rans.end()); return rans; } else if ((k < p) || (sum < l)) { k++; if (k >= n) break; ans.push_back(local_w[k][1]); sum += local_w[k][0]; } else if (sum > u) { // remove first element. ans.pop_front(); sum -= local_w[p][0]; p++; } } return std::vector<int32_t>(0); } #ifdef GARY_DBG void solve() { int n; std::cin >> n; std::vector<int> w(n); for (auto& a : w) { std::cin >> a; } int l, u; std::cin >> l >> u; const auto res = find_subset(l, u, w); if (res.size() == 0) { std::cout << "RETURNED EMPTY VECTOR (...)\n"; return; } std::cout << "res ~> "; for (const auto& a : res) { std::cout << a << " "; } std::cout << '\n'; // check if condition met: int sum = 0; for (const auto& a : res) { sum += w[a]; } if (l <= sum && sum <= u) { std::cout << "YES: SOLUTION CORRECT\n"; } else { std::cout << "l: " << l << " | u: " << u << " " << " | got: " << sum << '\n'; } std::cout << l << " <= " << sum << " <= " << u << '\n'; } int32_t main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); int t = 1; // std::cin >> t; for (; t > 0; t--) { solve(); } 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...