Submission #1072273

#TimeUsernameProblemLanguageResultExecution timeMemory
1072273LCJLYDetecting Molecules (IOI16_molecules)C++14
69 / 100
3 ms628 KiB
#include <bits/stdc++.h>
#include "molecules.h"
//#include "grader.cpp"
using namespace std;

#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef array<int,4>pi2;

vector<int>find_subset(int l, int u, vector<int>w){
	int n=w.size();
	int counter=0;
	int ptr=-1;
	pii arr[n];
	for(int x=0;x<n;x++) arr[x]={w[x],x};
	sort(arr,arr+n);
	for(int x=0;x<n;x++){
		if(counter+arr[x].first>u) break;
		counter+=arr[x].first;
		ptr=x;
	}
	//show(counter,counter);
	vector<int>ans;
	if(ptr==-1) return ans;
	else if(counter>=l){
		for(int y=0;y<=ptr;y++) ans.push_back(arr[y].second);
		return ans;
	}
	int cur=n-1;
	for(int x=ptr;x>=0;x--){
		counter+=arr[cur].first;
		counter-=arr[x].first;
		//cur--;
		//show2(x,x,counter,counter);
		if(counter>=l&&counter<=u){
			for(int y=0;y<x;y++){
				ans.push_back(arr[y].second);
			}
			for(int y=n-1;y>=cur;y--){
				ans.push_back(arr[y].second);
			}
			return ans;
		}	
		cur--;
	}
	return ans;
}
#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...