# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
619922 | yanndev | Scales (IOI15_scales) | C++17 | 1 ms | 256 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>
using namespace std;
mt19937 rng(4589);
int mx = -1;
map<pair<int, int>, bool> comp {};
void init(int T) {
/* ... */
}
bool comp1(int a, int b) {
if (a == b)
return false;
if (comp.find({a, b}) != comp.end())
return comp[{a, b}];
/*int c = a;
while (c == a || c == b)
c = (rng() % 6) + 1;*/
int c = -1;
for (int i = 1; i <= 6; i++)
if (i != a && i != b)
c = i;
vector<int> ls {a, b, c};
int small = getLightest(a, b, c);
for (auto& x: ls) {
if (x != small) {
comp[{small, x}] = true;
comp[{x, small}] = false;
}
}
if (a == small)
return true;
if (b == small)
return false;
int big = getHeaviest(a, b, c);
for (auto& x: ls) {
if (x != big) {
comp[{x, big}] = true;
comp[{big, x}] = false;
}
}
if (a == big)
return false;
if (b == big)
return true;
}
bool comp2(int a, int b) {
if (a == b)
return false;
if (comp.find({a, b}) != comp.end())
return comp[{a, b}];
int small = getLightest(a, b, mx);
comp[{a, b}] = small == a;
comp[{b, a}] = small != a;
return small == a;
}
void orderCoins() {
/* ... */
int W[] = {1, 2, 3, 4, 5, 6};
shuffle(W, W + 6, rng);
comp.clear();
vector<int> cur {};
for (int i = 0; i < 6; i++) {
if ((int)cur.size() < 3) {
cur.push_back(W[i]);
}
if ((int)cur.size() == 3) {
mx = getHeaviest(cur[0], cur[1], cur[2]);
for (int j = 0; j <= i; j++) {
if (W[j] != mx) {
comp[{mx, W[j]}] = false;
comp[{W[j], mx}] = true;
}
}
cur = {mx};
}
}
if ((int)cur.size() > 1) {
for (int i = 0; (int)cur.size() < 3 && i < 6; i++) {
if (find(cur.begin(), cur.end(), W[i]) == cur.end()) {
cur.push_back(W[i]);
}
}
mx = getHeaviest(cur[0], cur[1], cur[2]);
}
for (int i = 1; i <= 6; i++) {
if (i != mx) {
comp[{i, mx}] = true;
comp[{mx, i}] = false;
}
}
//cout << "mx is " << mx << '\n';
stable_sort(W, W + 6, comp2);
answer(W);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |