Submission #500587

#TimeUsernameProblemLanguageResultExecution timeMemory
500587InternetPerson10Detecting Molecules (IOI16_molecules)C++17
100 / 100
53 ms8652 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; vector<pair<int, int>> ps; vector<int> ans; vector<ll> s, p; vector<int> find_subset(int l, int u, std::vector<int> w) { ll x = 0, g = -1; ps.resize(w.size()); for(int i = 0; i < w.size(); i++) { ps[i] = {w[i], i}; } sort(ps.begin(), ps.end()); for(int i = 0; i < w.size(); i++) { w[i] = ps[i].first; } s.resize(w.size()); p.resize(w.size()); for(int i = 0; i < w.size(); i++) { if(i == 0) s[i] = w[i]; else s[i] = s[i-1] + w[i]; } for(int i = w.size() - 1; i >= 0; i--) { if(i == w.size() - 1) p[w.size() - 1 - i] = w[i]; else p[w.size() - 1 - i] = p[w.size() - 2 - i] + w[i]; } for(int i = 0; i < w.size(); i++) { if(max((ll)l, s[i]) <= min((ll)u, p[i])) { ans.resize(i+1); for(int j = 0; j <= i; j++) ans[j] = j; for(int j = 0; j <= i; j++) x += (ll)w[j]; g = i; while(x < l) { x -= w[ans[g]]; ans[g] = (g - i) + w.size() - 1; x += w[ans[g]]; g--; } for(int j = 0; j <= i; j++) ans[j] = ps[ans[j]].second; return ans; } } return vector<int>(0); }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:15:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |         for(int i = 0; i < w.size(); i++)  {
      |                        ~~^~~~~~~~~~
molecules.cpp:19:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |         for(int i = 0; i < w.size(); i++) {
      |                        ~~^~~~~~~~~~
molecules.cpp:24:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         for(int i = 0; i < w.size(); i++) {
      |                        ~~^~~~~~~~~~
molecules.cpp:29:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |             if(i == w.size() - 1) p[w.size() - 1 - i] = w[i];
      |                ~~^~~~~~~~~~~~~~~
molecules.cpp:32:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for(int i = 0; i < w.size(); i++) {
      |                        ~~^~~~~~~~~~
#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...