# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
550524 | elazarkoren | Scales (IOI15_scales) | C++17 | 1 ms | 212 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"
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
mt19937 rng(time(0));
void init(int T) {
}
map<vi, int> asksLight;
int queryLight(int a, int b, int c) {
vi v = {a, b, c};
sort(all(v));
if (asksLight.count(v)) return asksLight[v];
return asksLight[v] = getLightest(a, b, c);
}
map<vi, int> asksHeavy;
int queryHeavy(int a, int b, int c) {
vi v = {a, b, c};
sort(all(v));
if (asksHeavy.count(v)) return asksHeavy[v];
return asksHeavy[v] = getHeaviest(a, b, c);
}
map<vi, int> asksMed;
int queryMed(int a, int b, int c) {
vi v = {a, b, c};
sort(all(v));
if (asksMed.count(v)) return asksMed[v];
return asksMed[v] = getMedian(a, b, c);
}
map<vi, int> asksNext;
int queryNext(int a, int b, int c, int d) {
vi v = {a, b, c};
sort(all(v));
v.push_back(d);
if (asksNext.count(v)) return asksNext[v];
return asksNext[v] = getNextLightest(a, b, c, d);
}
vi Sort4(vi v) {
int x = queryLight(v[0], v[1], v[2]);
if (x == v[1]) swap(v[0], v[1]);
else if (x == v[2]) swap(v[0], v[2]);
x = queryHeavy(v[1], v[2], v[3]);
if (x == v[2]) swap(v[3], v[2]);
else if (x == v[1]) {
swap(v[1], v[2]);
swap(v[3], v[2]);
}
x = queryMed(v[0], v[1], v[2]);
vi ans;
if (x == v[0]) {
ans = {v[2], v[0], v[1], v[3]};
} else if (x == v[1]) {
ans = {v[0], v[1], v[2], v[3]};
} else {
ans = {v[0], v[2], v[1], v[3]};
}
return ans;
}
vi Sort5(vi v) {
int x = v.back();
v.pop_back();
v = Sort4(v);
int y = queryMed(v[0], v[1], x);
vi ans;
if (y == v[0]) {
ans = {x, v[0], v[1], v[2], v[3]};
} else if (y == x) {
ans = {v[0], x, v[1], v[2], v[3]};
} else {
y = queryMed(v[2], v[3], x);
if (y == v[2]) {
ans = {v[0], v[1], x, v[2], v[3]};
} else if (y == x) {
ans = {v[0], v[1], v[2], x, v[3]};
} else {
ans = {v[0], v[1], v[2], v[3], x};
}
}
return ans;
}
vi Sort6() {
vi v = {1, 2, 3, 4, 5, 6};
shuffle(all(v), rng);
int x = v.back();
v.pop_back();
v = Sort5(v);
int y = queryNext(v[1], v[2], v[3], x);
vi ans;
if (y == v[2]) {
ans = {v[0], v[1], x, v[2], v[3], v[4]};
} else if (y == v[3]) {
ans = {v[0], v[1], v[2], x, v[3], v[4]};
} else {
y = queryMed(v[0], v[4], x);
if (y == v[0]) {
ans = {x, v[0], v[1], v[2], v[3], v[4]};
} else if (y == v[4]) {
ans = {v[0], v[1], v[2], v[3], v[4], x};
} else {
y = queryMed(v[0], v[1], x);
if (y == x) {
ans = {v[0], x, v[1], v[2], v[3], v[4]};
} else {
ans = {v[0], v[1], v[2], v[3], x, v[4]};
}
}
}
return ans;
}
void orderCoins() {
int w[] = {1, 2, 3, 4, 5, 6};
// shuffle(w, w + 6, rng);
asksLight.clear();
asksHeavy.clear();
asksMed.clear();
asksNext.clear();
vi v = Sort6();
for (int i = 0; i < 6; i++) {
w[i] = v[i];
}
answer(w);
}
//1
//3 4 6 2 1 5
//1
//2 3 1 5 6 4
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |