Submission #330086

# Submission time Handle Problem Language Result Execution time Memory
330086 2020-11-23T19:43:14 Z saarthak Detecting Molecules (IOI16_molecules) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

vector<int> w;

int[] find_subset(int l, int u, int[] w) {
	if(u == l) return {w[0]};				//if the range is 0, all weights are same, return any
	
	int total_weight = 0, i = 0;
	queue<int> indices;
	
	sort(w.begin(), w.end());
	
	while(total_weight < l) {
		total_weight += w[i];
		indices.push(i++);
	}
	i = 0;
	while(total_weight > u) {
		total_weight -= w[i++];
		indices.pop();
	}
	
	if(total_weight < l || total_weight > u) return int[];		//no subarray found
	
	int ans[indices.size()];
  	i = 0;
	while(!indices.empty()) {
		ans[i++] = indices.front();
		indices.pop();
	}
	return ans;
}

Compilation message

molecules.cpp:7:4: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
    7 | int[] find_subset(int l, int u, int[] w) {
      |    ^
molecules.cpp:7:4: error: structured binding declaration cannot have type 'int'
    7 | int[] find_subset(int l, int u, int[] w) {
      |    ^~
molecules.cpp:7:4: note: type must be cv-qualified 'auto' or reference to cv-qualified 'auto'
molecules.cpp:7:4: error: empty structured binding declaration
molecules.cpp:7:7: error: expected initializer before 'find_subset'
    7 | int[] find_subset(int l, int u, int[] w) {
      |       ^~~~~~~~~~~