Submission #244137

# Submission time Handle Problem Language Result Execution time Memory
244137 2020-07-02T16:22:27 Z dCoding Detecting Molecules (IOI16_molecules) C++14
0 / 100
5 ms 384 KB
#include "bits/stdc++.h"
#include "molecules.h"

#define F0R(i,n) for(auto i = 0; i < (n); i++)
#define FOR(i,a,b) for(auto i = (a); i <= (b); i++)
#define ROF(i,a,b) for(auto i = (a); i >= (b); i--)
#define pb push_back
#define vi vector<int> 
#define pii pair<int,int>
#define F first
#define S second
#define ll long long

using namespace std;

vi find_subset(int l,int u,vi w) {
	vector<pii> a;
	int n = w.size();
	F0R(i,n) {
		a.pb(make_pair(w[i],i));
	}
	sort(a.begin(),a.end());
	ll pre[n];
	pre[0] = a[0].F;
	FOR(i,1,n-1) pre[i] = pre[i-1]+a[i].F;
	vi ans;
	int lo = 0, hi = n-1;
	bool found = false;


	int highestIndex = 0;
	ll sum = 0;
	F0R(i,n) {
		highestIndex = i;
		sum += a[i].F;
		if(sum >= u) {
			break;
		} 
	}

	int lowestIndex = 0;
	F0R(i,n) {
		if(sum >= l && sum <= u) {
			found = true;
			lowestIndex = i;
			break;
		} 
		sum -= a[i].F;
	}

	if(!found || lowestIndex > highestIndex) return ans;

	FOR(i,lowestIndex,highestIndex) ans.pb(a[i].S+1);
	return ans; 
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:27:6: warning: unused variable 'lo' [-Wunused-variable]
  int lo = 0, hi = n-1;
      ^~
molecules.cpp:27:14: warning: unused variable 'hi' [-Wunused-variable]
  int lo = 0, hi = n-1;
              ^~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB OK (n = 1, answer = NO)
2 Correct 5 ms 384 KB OK (n = 1, answer = NO)
3 Incorrect 5 ms 256 KB Integer 1 violates the range [0, 0]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 256 KB Contestant can not find answer, jury can
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB OK (n = 1, answer = NO)
2 Correct 5 ms 384 KB OK (n = 1, answer = NO)
3 Incorrect 5 ms 256 KB Integer 1 violates the range [0, 0]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB OK (n = 1, answer = NO)
2 Correct 5 ms 384 KB OK (n = 1, answer = NO)
3 Incorrect 5 ms 256 KB Integer 1 violates the range [0, 0]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB OK (n = 1, answer = NO)
2 Correct 5 ms 384 KB OK (n = 1, answer = NO)
3 Incorrect 5 ms 256 KB Integer 1 violates the range [0, 0]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB OK (n = 1, answer = NO)
2 Correct 5 ms 384 KB OK (n = 1, answer = NO)
3 Incorrect 5 ms 256 KB Integer 1 violates the range [0, 0]
4 Halted 0 ms 0 KB -