Submission #500722

#TimeUsernameProblemLanguageResultExecution timeMemory
500722aryan12Detecting Molecules (IOI16_molecules)C++17
100 / 100
51 ms8204 KiB
#include "molecules.h" #include <bits/stdc++.h> using namespace std; bool cmp(pair<long long, long long> a, pair<long long, long long> b) { return a.first < b.first; } vector<int> find_subset(int l, int r, vector<int> w) { vector<pair<long long, long long> > a; for(long long i = 0; i < w.size(); i++) { a.push_back(make_pair(w[i], i)); } sort(a.begin(), a.end(), cmp); long long left = 0, right = 0, sum = a[0].first; for(long long i = 1; i < a.size(); i++) { sum += a[i].first; if(sum > r) { break; } right = i; } vector<int> ans; if(sum >= l && sum <= r) { for(long long i = 0; i <= right; i++) { ans.push_back(a[i].second); } } else { int f = 0; sum = 0; left = 0, right = -1; int x = a.size() - 1; for(left = 0; left < a.size(); left++) { if(left != 0) sum -= a[left - 1].first; //cout << "right = " << right << ", a.size() - 1 = " << a.size() - 1 << ", sum + a[right + 1].first = " << sum + a[right + 1].first << ", r = " << r << "\n"; while(right < x && sum + a[right + 1].first <= r) { //cout << "party all night\n"; right++; sum += a[right].first; } //cout << "left = " << left << ", right = " << right << "\n"; if(sum >= l && sum <= r) { f = 1; break; } } if(f == 1) { for(long long i = left; i <= right; i++) { ans.push_back(a[i].second); } } } return ans; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:11:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(long long i = 0; i < w.size(); i++) {
      |                          ~~^~~~~~~~~~
molecules.cpp:16:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(long long i = 1; i < a.size(); i++) {
      |                          ~~^~~~~~~~~~
molecules.cpp:34:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for(left = 0; left < a.size(); left++) {
      |                       ~~~~~^~~~~~~~~~
#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...