Submission #800520

#TimeUsernameProblemLanguageResultExecution timeMemory
800520BoasDetecting Molecules (IOI16_molecules)C++17
9 / 100
1 ms304 KiB
#include "molecules.h" using namespace std; #include <bits/stdc++.h> #define MAX_N 200001 #define ALL(x) x.begin(), x.end() #define loop(x) for (int i = 0; i < (x); i++) typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<int> vi; vi find_subset(int l, int u, vi w) { vii sortedW; loop(w.size()) { if (w[i] > u) continue; sortedW.push_back({w[i], i}); } sort(ALL(sortedW)); vi used; bitset<MAX_N> usin; int totalW = 0; while (totalW < l) { bool added = false; for (int i = sortedW.size() - 1; i >= 0; i--) { if (usin[i]) continue; const auto &[W, ix] = sortedW[i]; if (totalW + W > u) { continue; } added = true; used.push_back(ix); usin[i] = true; totalW += W; sortedW.erase(sortedW.begin() + i); } if (!added) break; } if (totalW >= l) return used; if (sortedW.size() < 2) return {}; const auto &[W, ix] = sortedW[0]; used.push_back(ix); totalW += W; usin[0] = true; vi oldUsed(used); bitset<MAX_N> oldUsin(usin); int oldW = totalW; for (int i1 = 0; i1 < sortedW.size(); i1++) { if (used[i1]) continue; ii p1 = sortedW[i1]; for (int i2 : oldUsed) { ii p2 = sortedW[i2]; used = oldUsed; used[find(ALL(used), p2.second) - used.begin()] = p1.second; totalW = oldW - p2.first + p1.first; if (totalW > u) continue; while (totalW < l) { bool added = false; for (int i = sortedW.size() - 1; i >= 0; i--) { if (usin[i]) continue; const auto &[W, ix] = sortedW[i]; if (totalW + W > u) { continue; } added = true; used.push_back(ix); usin[i] = true; totalW += W; sortedW.erase(sortedW.begin() + i); } if (!added) break; } if (totalW >= l) return used; } } return {}; }

Compilation message (stderr)

molecules.cpp: In function 'vi find_subset(int, int, vi)':
molecules.cpp:8:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define loop(x) for (int i = 0; i < (x); i++)
      |                                 ~~^~~~~
molecules.cpp:16:5: note: in expansion of macro 'loop'
   16 |     loop(w.size())
      |     ^~~~
molecules.cpp:58:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for (int i1 = 0; i1 < sortedW.size(); i1++)
      |                      ~~~^~~~~~~~~~~~~~~~
#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...