제출 #291413

#제출 시각아이디문제언어결과실행 시간메모리
291413shayan_pDetecting Molecules (IOI16_molecules)C++17
100 / 100
64 ms6252 KiB
// Oh damn! Suddenly you're free to fly...

#include<bits/stdc++.h>
#include "molecules.h"

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int maxn = 2e5 + 10, mod = 1e9 + 7, inf = 1e9 + 10;

vector<int> find_subset(int L, int R, vector<int> a){
    int n = sz(a);
    vector<pii> vec;
    for(int i = 0; i < n; i++)
	vec.PB({a[i], i});
    sort(vec.begin(), vec.end());
    for(int i = 0; i < n; i++)
	a[i] = vec[i].F;
    
    ll sm = 0;
    int pt = 0;
    while(pt < n && sm < L){
	sm+= a[pt];
	pt++;
    }
    vector<int> ans;
    if(L <= sm && sm <= R){
	for(int i = 0; i < pt; i++)
	    ans.PB(vec[i].S);
	return ans;
    }
    if(sm < L){
	return ans;
    }
    sm-= a[--pt];
    int lst = n-1;
    for(int i = pt-1; i >= 0; lst--, i--){
	if(sm - a[i] + a[lst] < L){
	    sm-= a[i];
	    sm+= a[lst];	    
	}
	else{
	    int pt2 = i;
	    while(sm < L)
		sm-= a[pt2], sm+= a[++pt2];
	    for(int j = 0; j < i; j++)
		ans.PB(vec[j].S);
	    ans.PB(vec[pt2].S);
	    for(int j = lst + 1; j < n; j++)
		ans.PB(vec[j].S);
	    return ans;
	}
    }
    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...