# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1039121 | c2zi6 | Scales (IOI15_scales) | C++14 | 1 ms | 604 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.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "scales.h"
void init(int T) {
}
void answer(VI ans);
void orderCoins() {
auto restf = [&](VI vec, int lim = 6){
VI ret;
replr(i, 1, lim) {
for (int x : vec) if (i == x) goto dontadd;
ret.pb(i);
dontadd:;
}
return ret;
};
VI rel;
/* relative order of 1, 2, 3, 4 */
int mn = getLightest(1, 2, 3);
VI rest = restf({mn}, 3);
int nxt = getNextLightest(rest[0], rest[1], 4, mn);
if (nxt == 4) {
if (getHeaviest(rest[0], rest[1], mn) == rest[0]) {
rel = VI{mn, 4, rest[1], rest[0]};
} else {
rel = VI{mn, 4, rest[0], rest[1]};
}
} else {
int rest = restf({mn, nxt}, 3)[0];
int med = getMedian(mn, rest, 4);
if (med == mn) {
rel = VI{4, mn, nxt, rest};
} else if (med == rest) {
rel = VI{mn, nxt, rest, 4};
} else if (med == 4) {
rel = VI{mn, nxt, 4, rest};
}
}
int med = getMedian(rel[0], 5, 6);
// minchev hmi ogtagorcac e 4 gorcoxutyun
if (med == 5) {
int med = getMedian(rel[2], 5, 6);
if (med == rel[2]) {
bool a = (getLightest(rel[1], 5, 6) == rel[1]);
bool b = (getHeaviest(rel[3], 5, 6) != rel[1]);
VI ans;
ans.pb(rel[0]);
if (a) {
ans.pb(rel[1]);
ans.pb(5);
} else {
ans.pb(5);
ans.pb(rel[1]);
}
ans.pb(rel[2]);
if (b) {
ans.pb(rel[3]);
ans.pb(6);
} else {
ans.pb(6);
ans.pb(rel[3]);
}
answer(ans);
return;
} else if (med == 5) {
int med = getMedian(rel[3], 5, 6);
if (med == rel[3]) {
answer({rel[0], rel[1], rel[2], 5, rel[3], 6});
return;
} else if (med == 5) {
answer({rel[0], rel[1], rel[2], rel[3], 5, 6});
return;
} else if (med == 6) {
answer({rel[0], rel[1], rel[2], 5, 6, rel[3]});
return;
}
}
} else if (med == 6) {
int med = getMedian(rel[2], 6, 5);
if (med == rel[2]) {
bool a = (getLightest(rel[1], 6, 5) == rel[1]);
bool b = (getHeaviest(rel[3], 6, 5) != rel[1]);
VI ans;
ans.pb(rel[0]);
if (a) {
ans.pb(rel[1]);
ans.pb(6);
} else {
ans.pb(6);
ans.pb(rel[1]);
}
ans.pb(rel[2]);
if (b) {
ans.pb(rel[3]);
ans.pb(5);
} else {
ans.pb(5);
ans.pb(rel[3]);
}
answer(ans);
return;
} else if (med == 6) {
int med = getMedian(rel[3], 6, 5);
if (med == rel[3]) {
answer({rel[0], rel[1], rel[2], 6, rel[3], 5});
return;
} else if (med == 6) {
answer({rel[0], rel[1], rel[2], rel[3], 6, 5});
return;
} else if (med == 5) {
answer({rel[0], rel[1], rel[2], 6, 5, rel[3]});
return;
}
}
} else {
int med = getMedian(rel[0], rel[1], 5);
if (med == 5) {
answer({6, rel[0], 5, rel[1], rel[2], rel[3]});
return;
} else if (med == rel[1]) {
int med = getMedian(rel[2], rel[3], 5);
if (med == 5) {
answer({6, rel[0], rel[1], rel[2], 5, rel[3]});
return;
} else if (med == rel[2]) {
answer({6, rel[0], rel[1], 5, rel[2], rel[3]});
return;
} else if (med == rel[3]) {
answer({6, rel[0], rel[1], rel[2], rel[3], 5});
return;
}
} else if (med == rel[0]) {
if (getLightest(rel[1], rel[2], 6) == 6) {
answer({5, rel[0], 6, rel[1], rel[2], rel[3]});
return;
} else {
int med = getMedian(rel[2], rel[3], 6);
if (med == rel[3]) {
answer({5, rel[0], rel[1], rel[2], rel[3], 6});
return;
} else if (med == 6) {
answer({5, rel[0], rel[1], rel[2], 6, rel[3]});
return;
} else if (med == rel[2]) {
answer({5, rel[0], rel[1], 6, rel[2], rel[3]});
return;
}
}
}
}
VI ans(6);
answer(ans);
}
void answer(VI ans) {
int w[6];
rep(i, 6) w[i] = ans[i];
answer(w);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |