Submission #302117

#TimeUsernameProblemLanguageResultExecution timeMemory
302117JPN20Detecting Molecules (IOI16_molecules)C++17
100 / 100
65 ms6648 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; long long N; pair<long long, int> W[1 << 18]; long long L, R; vector<int> solve(int pos) { long long sum = 0; long long idx = -1; for (int i = 0; i < pos; i++) sum += W[i].first; if (L <= sum && sum <= R) { idx = 0; } else { for (int i = 1; i <= pos; i++) { sum -= W[pos - i].first; sum += W[N - i].first; if (L <= sum && sum <= R) { idx = i; break; } } } if (idx == -1) return vector<int> {}; vector<int> vec; for (int i = 0; i < pos - idx; i++) vec.push_back(W[i].second); for (int i = 0; i < idx; i++) vec.push_back(W[N - 1 - i].second); sort(vec.begin(), vec.end()); return vec; } vector<int> find_subset(int l, int u, vector<int> w) { N = w.size(); L = l; R = u; for (int i = 0; i < N; i++) W[i] = make_pair(w[i], i); sort(W, W + N); // CALC1 long long val = 0, cnt = -1; for (int i = 0; i < N; i++) { val += W[i].first; if (val >= l) { cnt = i + 1; break; } } if (cnt == -1) return vector<int>{}; // CALC2 vector<int> V1 = solve(cnt - 1); vector<int> V2 = solve(cnt); if (V1.size() >= 1) return V1; if (V2.size() >= 1) return V2; 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...