Submission #397262

#TimeUsernameProblemLanguageResultExecution timeMemory
397262peuchDetecting Molecules (IOI16_molecules)C++17
Compilation error
0 ms0 KiB
#include <cstdio> #include <vector> #include <cassert> #include "molecules.h" #include "molecules.h" #include<bits/stdc++.h> using namespace std; vector<int> getAns(vector<pair<int, int> > aux, int ini, int fim); std::vector<int> find_subset(int l, int u, std::vector<int> w) { int n = w.size(); vector<int> ret; vector<pair<int, int> > aux; for(int i = 0; i < w.size(); i++) aux.push_back(make_pair(w[i], i)); sort(aux.begin(), aux.end()); vector<int> suf, pref; suf.push_back(aux[0].first); pref.push_back(aux[n - 1].first); for(int i = 1; i < n; i++) suf.push_back(suf[suf.size() - 1] + aux[i].first); for(int i = n - 2; i >= 0; i--) pref.push_back(pref[pref.size() - 1] + aux[i].first); if(suf[n - 1] < l) return ret; if(suf[0] > u) return ret; if(suf[n - 1] <= u) return getAns(aux, n - 1, n - 1); for(int i = 0; i < n; i++){ if(suf[i] > u) break; if(suf[i] >= l) return getAns(aux, i, n + 1); int k = lower_bound(pref.begin(), pref.end(), l - suf[i]) - pref.begin(); if(k == pref.size()) continue; if(k + 1 + i + 1 > n) continue; if(suf[i] + pref[k] > u) continue; if(suf[i] + pref[k] < l) continue; k = n - 1 - k; if(k <= i) continue; return getAns(aux, i, k); } int k = lower_bound(pref.begin(), pref.end(), l) - pref.begin(); if(k == pref.size()) return ret; if(pref[k] > u) return ret; if(pref[k] < l) return ret; k = n - 1 - k; return getAns(aux, -1, k); } vector<int> getAns(vector<pair<int, int> > aux, int ini, int fim){ vector<int> ret; for(int i = 0; i <= ini; i++) ret.push_back(aux[i].second); for(int i = aux.size() - 1; i >= fim; i--) ret.push_back(aux[i].second); sort(ret.begin(), ret.end()); return ret; } int main() { int n, l, u; assert(3 == scanf("%d %d %d", &n, &l, &u)); std::vector<int> w(n); for (int i = 0; i < n; i++) assert(1 == scanf("%d", &w[i])); std::vector<int> result = find_subset(l, u, w); printf("%d\n", (int)result.size()); for (int i = 0; i < (int)result.size(); i++) printf("%d%c", result[i], " \n"[i == (int)result.size() - 1]); }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:17:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  for(int i = 0; i < w.size(); i++)
      |                 ~~^~~~~~~~~~
molecules.cpp:40:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   if(k == pref.size()) continue;
      |      ~~^~~~~~~~~~~~~~
molecules.cpp:51:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   if(k == pref.size()) return ret;
      |      ~~^~~~~~~~~~~~~~
/tmp/cc35uhPo.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccz9dD9X.o:molecules.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status