# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
835176 | MadokaMagicaFan | Scales (IOI15_scales) | C++14 | 1 ms | 336 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"
#include "scales.h"
using namespace std;
#define pb push_back
#ifndef ONPC
mt19937 rng(time(NULL));
#endif
void init(int T) {
}
int cnt = 0;
void order(vector<int> &a) {
cnt += 2;
int x = getLightest(a[0], a[1], a[2]);
int y = getMedian(a[0], a[1], a[2]);
a[2] = a[2] + a[1] + a[0] - x - y;
a[0] = x;
a[1] = y;
}
void add3(vector<int> &a, int x) {
++cnt;
int u = getMedian(a[1], a[2], x);
if (u == a[2]) {
a.push_back(x); return;
}
if (u == x) {
a.push_back(x);
swap(a[2], a[3]);
return;
}
u = getMedian(a[0], a[1], x);
++cnt;
a.push_back(x);
swap(a[2], a[3]);
swap(a[1], a[2]);
if (u == a[0]) swap(a[0], a[1]);
}
void add2(vector<int> &a, int x) {
int u = getMedian(a[0], a[1], x);
a.push_back(x);
if (u == a[1]) return;
swap(a[1], a[2]);
if (u == x) return;
swap(a[0], a[1]);
}
vector<int> cmp(vector<int> a, vector<int> b, int it) {
vector<int> res;
int z = getNextLightest(a[0], a[1], a[2], b[1]);
++cnt;
int p;
vector<int> u, v;
if (z == a[1]) {
u = {a[0], b[1]};
v = {a[1], a[2]};
add2(u, b[0]); add2(v,b[2]);
for (auto x : v) u.pb(x);
return u;
} else if (z == a[2]) {
u = {a[0], a[1]};
v = {b[1], a[2]};
add2(u, b[0]); add2(v,b[2]);
for (auto x : v) u.pb(x);
return u;
}
if (it == 0) return cmp(b, a, 1);
a.pb(b[0]);
a.pb(b[1]);
a.pb(b[2]);
z = getMedian(a[0], a[3], a[5]);
cnt++;
if (z == a[0]) {
res = {a[3], a[4], a[0], a[5], a[1], a[2]};
return res;
}
if (z == a[5]) {
res = {a[3], a[4], a[5], a[0], a[1], a[2]};
return res;
}
z = getMedian(a[2], a[3], a[4]);
cnt++;
if (z == a[2]) {
swap(a[3], a[2]);
}
return a;
}
void orderCoins() {
int ans[6];
vector<int> a(6);
iota(a.begin(), a.end(), 1);
#ifndef ONPC
shuffle(a.begin(), a.end(), rng);
#endif
vector<int> c = a;
vector<int> b;
b.pb(c.back());
c.pop_back();
b.pb(c.back());
c.pop_back();
b.pb(c.back());
c.pop_back();
order(b); order(c);
a = cmp(b, c, 0);
for (int i = 0; i < 6; ++i)
ans[i] = a[i];
answer(ans);
// cout << cnt << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |