# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41736 | funcsr | Scales (IOI15_scales) | C++14 | 2 ms | 828 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 "scales.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <cassert>
#include <deque>
using namespace std;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define index(x, y) (int)(lower_bound(all(x), y) - x.begin())
#define pb push_back
#define _1 first
#define _2 second
typedef pair<int, int> P;
void init(int T) {}
deque<int> sort3(vector<int> a) {
assert(a.size() == 3);
int lo = getLightest(a[0], a[1], a[2]);
int hi = getHeaviest(a[0], a[1], a[2]);
int rest = -1;
for (int x : a) if (x != lo && x != hi) rest = x;
return {lo, rest, hi};
}
void orderCoins() {
deque<int> L = sort3({1, 2, 3}),
R = sort3({4, 5, 6});
vector<int> ret;
while (!L.empty() && !R.empty()) {
if (L.size() == 1 && R.size() == 1) {
assert(ret.size());
int mx = getHeaviest(ret[0], L.front(), R.front());
ret.pb(L.front()==mx?R.front():L.front());
ret.pb(mx);
L.clear();
R.clear();
continue;
}
if (R.size() == 1) swap(L, R);
int med = getMedian(L[0], R[0], R[1]);
if (med == L[0]) {
ret.pb(R[0]);
ret.pb(L[0]);
L.pop_front();
R.pop_front();
}
else if (med == R[1]) {
ret.pb(R[0]);
ret.pb(R[1]);
R.pop_front();
R.pop_front();
}
else if (med == R[0]) {
ret.pb(L[0]);
L.pop_front();
}
else abort();
}
while (!L.empty()) ret.pb(L.front()), L.pop_front();
while (!R.empty()) ret.pb(R.front()), R.pop_front();
assert(ret.size() == 6);
int W[] = {ret[0], ret[1], ret[2], ret[3], ret[4], ret[5]};
answer(W);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |