제출 #802819

#제출 시각아이디문제언어결과실행 시간메모리
802819BoasDetecting Molecules (IOI16_molecules)C++17
0 / 100
1 ms340 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; typedef set<int> si; 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)); si 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.insert(i); usin[i] = true; totalW += W; } if (!added) break; } if (totalW >= l) { vi ret; for (int i : used) { ret.push_back(sortedW[i].second); } return ret; } // if (sortedW.size() < 2) return {}; const auto &[W, ix] = sortedW[0]; used.insert(0); totalW += W; usin[0] = true; si oldUsed(used); // sorted indexes bitset<MAX_N> oldUsin(usin); // sorted indexes int oldW = totalW; for (int i1 = 0; i1 < sortedW.size(); i1++) { if (usin[i1]) continue; ii p1 = sortedW[i1]; for (int i2 : oldUsed) { ii p2 = sortedW[i2]; used = oldUsed; used.erase(i2); used.insert(i1); 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.insert(i); usin[i] = true; totalW += W; } if (!added) break; } if (totalW >= l) { vi ret; for (int i : used) { ret.push_back(sortedW[i].second); } return ret; } } } return {}; }

컴파일 시 표준 에러 (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:17:5: note: in expansion of macro 'loop'
   17 |     loop(w.size())
      |     ^~~~
molecules.cpp:64: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]
   64 |     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...