Submission #394523

#TimeUsernameProblemLanguageResultExecution timeMemory
394523idk321Detecting Molecules (IOI16_molecules)C++11
100 / 100
68 ms6180 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; std::vector<int> find_subset(int l, int u, std::vector<int> w) { ll lsum = 0; ll rsum = 0; vector<int> res; vector<array<int, 2>> withIndex; for (int i = 0; i < w.size(); i++) { withIndex.push_back({w[i], i}); } sort(withIndex.begin(), withIndex.end()); for (int i = 0; i < withIndex.size(); i++) { lsum += withIndex[i][0]; rsum += withIndex[withIndex.size() - 1 - i][0]; if (lsum <= u && rsum >= l) { int a = 0; int b = a + i; while (res.size() < i + 1) { while (b + 1 < withIndex.size() && lsum - withIndex[a][0] + withIndex[b + 1][0] <= u) { lsum = lsum - withIndex[a][0] + withIndex[b + 1][0]; a++; b++; } res.push_back(withIndex[a][1]); a++; } break; } } return res; } /* 7 15 16 5 5 5 5 6 6 6 */

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for (int i = 0; i < w.size(); i++)
      |                     ~~^~~~~~~~~~
molecules.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int i = 0; i < withIndex.size(); i++)
      |                     ~~^~~~~~~~~~~~~~~~~~
molecules.cpp:27:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |             while (res.size() < i + 1)
      |                    ~~~~~~~~~~~^~~~~~~
molecules.cpp:29:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |                 while (b + 1 < withIndex.size() && lsum - withIndex[a][0] + withIndex[b + 1][0] <= u)
      |                        ~~~~~~^~~~~~~~~~~~~~~~~~
#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...