# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
138370 | arthurconmy | Detecting Molecules (IOI16_molecules) | C++14 | 70 ms | 10356 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#ifndef ARTHUR_LOCAL
#include "molecules.h"
#endif
using namespace std;
using ll = long long;
vector<int> find_subset(int u, int d, vector<int> W_raw)
{
int n = W_raw.size();
int l = ll(u);
int r = ll(d);
vector<pair<ll,int>> W;
for(int i=0; i<n; i++)
{
W.push_back(make_pair(ll(W_raw[i]),i));
}
sort(W.begin(),W.end());
ll cur1=0;
ll cur2=0;
vector<int> v1;
vector<int> v2;
bool works=0;
for(int i=1; i<=n; i++)
{
cur1 += W[i-1].first;
v1.push_back(W[i-1].second);
cur2 += W[n-i].first;
v2.push_back(W[n-i].second);
if(cur1 >= l && cur1 <= r)
{
// return cur1 things
return v1;
}
if(cur2 >= l && cur2 <= r)
{
return v2;
}
if(cur1 < l && cur2 > r) // LOOKS DODGY, PROBABLY IS RIGHT
{
works=1;
break;
}
}
if(!works) return {};
// definitely at this point
for(int i=0; i<v1.size(); i++)
{
cur2 -= ll(W_raw[v2[v1.size()-i-1]]);
cur2 += ll(W_raw[v1[i]]); // after this update, cur2 decreases by at most
v2[v1.size()-i-1]=v1[i];
if(cur2 <= r && cur2 >= l) return v2;
}
return {};
}
#ifdef ARTHUR_LOCAL
int main()
{
vector<int> V = find_subset(50,51,{25,26});
cout << V.size() << endl;
for(auto v:V) cout << v << " ";
}
#endif
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |