# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
606901 | yuto1115 | Scales (IOI15_scales) | C++17 | 1 ms | 300 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 "bits/stdc++.h"
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, s, n) for(ll i = ll(s); i < ll(n); ++i)
#define rrep(i, n) for(ll i = ll(n)-1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define SZ(a) int(a.size())
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;
const int inf = 1001001001;
const ll linf = 1001001001001001001;
template<class T>
bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T>
bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
void init(int t) {}
void orderCoins() {
int w[] = {1, 2, 3, 4, 5, 6};
w[0] = getLightest(1, 2, 3);
w[2] = getHeaviest(1, 2, 3);
w[1] = 6 - w[0] - w[2];
int now = getMedian(4, 5, 6);
if (now == 4) swap(w[3], w[4]);
else if (now == 6) swap(w[5], w[4]);
auto fix = [&](int a, int b, int c) {
assert(0 <= a and a <= b and b <= c and c <= 3);
vvi v(7);
rep(i, 3) v[2 * i + 1].pb(w[i]);
v[2 * a].pb(w[3]);
v[2 * b].pb(w[4]);
v[2 * c].pb(w[5]);
vi nw;
rep(i, 7) nw.insert(nw.end(), all(v[i]));
rep(i, 6) w[i] = nw[i];
};
now = getNextLightest(w[0], w[1], w[2], w[4]);
if (now == w[1] or now == w[2]) {
if (getLightest(w[3], w[4], w[5]) != w[3]) swap(w[3], w[5]);
vi rev(4);
rep(i, 3) rev[w[i]] = i;
int a = rev[getNextLightest(w[0], w[1], w[2], w[3])];
int b = rev[now];
int c = rev[getNextLightest(w[0], w[1], w[2], w[5])];
if (!c) c = 3;
fix(a, b, c);
} else {
now = getNextLightest(w[2], w[3], w[5], w[4]);
if (now == w[2]) {
if (getLightest(w[3], w[4], w[5]) != w[3]) swap(w[3], w[5]);
fix(0, 0, 3);
} else {
if (now == w[3]) swap(w[3], w[5]);
now = getMedian(w[2], w[3], w[4]);
if (now == w[2]) {
now = getMedian(w[0], w[1], w[3]);
if (now == w[0]) fix(0, 3, 3);
else if (now == w[1]) fix(2, 3, 3);
else fix(1, 3, 3);
} else if (now == w[3]) {
fix(3, 3, 3);
} else {
now = getMedian(w[0], w[1], w[5]);
if (now == w[0]) fix(0, 0, 0);
else if (now == w[1]) fix(0, 0, 2);
else fix(0, 0, 1);
}
}
}
answer(w);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |