Submission #314410

#TimeUsernameProblemLanguageResultExecution timeMemory
314410LucaDantasDetecting Molecules (IOI16_molecules)C++17
100 / 100
82 ms3064 KiB
#include "molecules.h"
#include<bits/stdc++.h>
using namespace std;

#define all(a) a.begin(), a.end()
#define pb push_back

vector<int> find_subset(int l, int u, vector<int> w) {
	int n = (int)(w.size());
	vector<int> ind(n);
	for(int i = 0; i < n; i++)
		ind[i] = i;
	sort(all(ind), [&](int a, int b){
		return w[a] < w[b];
	});
	sort(all(w));
	unsigned int pref = 0, suf = 0;
	int i = 0;
	vector<int> ans;
	for(; i <= n && pref <= u; i++) {
		if(suf >= l) {
			deque<int> extra;
			for(int pos = n-i; pos < n; pos++)
				extra.pb(pos);
			while(suf > u) {
				suf -= w[extra.back()];
				extra.pop_back();
				extra.push_front(n-1-i);
				suf += w[n-1-i];
				i++;
			}
			for(auto it : extra)
				ans.pb(ind[it]);
			break;
		}
		if(i < n)
			pref += w[i],
			suf += w[n-1-i];
	}
	return ans;
}

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:20:23: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   20 |  for(; i <= n && pref <= u; i++) {
      |                  ~~~~~^~~~
molecules.cpp:21:10: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   21 |   if(suf >= l) {
      |      ~~~~^~~~
molecules.cpp:25:14: warning: comparison of integer expressions of different signedness: 'unsigned int' and 'int' [-Wsign-compare]
   25 |    while(suf > 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...