# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
767186 | caganyanmaz | 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>
#define pb push_back
#include "scales.h"
using namespace std;
//#define DEBUGGING
#ifdef DEBUGGING
#define debug(x) cout << #x << ": " << x << "\n";
#else
#define debug(x) 42
#endif
void init(int T)
{}
array<int, 3> find_other_values(int a, int b, int c)
{
int a1 = 6 - a - c;
int b2 = 4;
while (b2 == b) b2++;
int b3 = 4;
while (b3 == b || b3 == b2) b3++;
return array<int,3>({a1, b2, b3});
}
void orderCoins()
{
vector<int> v(3);
int a = getLightest(1, 2, 3);
int b = getLightest(4, 5, 6);
int c = 1;
while (c == a) c++;
auto [a1, b2, b3] = find_other_values(a, b, c);
int m = getMedian(a, b, c);
if (m == a)
{
v[0] = b, v[1] = a, v[2] = c;
int bb2 = getNextLightest(b, a, c, b2);
if (bb2 == b || bb2 == c)
{
int aa1 = getNextLightest(a, b2, c, a1);
int bpos = -1, cpos = 2;
if (bb2 == b)
{
bpos = v.size();
v.pb(b2);
}
else // bb2 == c
{
bpos = 2;
v.insert(v.begin() + 2, b2);
cpos = 3;
}
if (aa1 == a)
v.pb(a1);
else if (aa1 == b2)
v.insert(v.begin() + bpos, a1);
else // aa1 == c
v.insert(v.begin() + cpos, a1);
int bb3 = getNextLightest(v[0], v[1], v[2], b3);
if (bb3 == v[1])
v.insert(v.begin() + 1, b3);
else if (bb3 == v[2])
v.insert(v.begin() + 2, b3);
else // This is where we get fucked (7th search possibility)
{
bb3 = getNextLightest(v[2], v[3], v[4], b3);
if (bb3 == v[2])
v.pb(b3);
else if (bb3 == v[3])
v.insert(v.begin() + 3, b3);
else // bb3 == v[4]
v.insert(v.begin() + 4, b3);
}
}
else // bb2 == a
{
v.insert(v.begin() + 1, b2);
int mx = getHeaviest(a1, c, b3);
if (mx == a1)
{
debug("bye");
int bb3 = getNextLightest(v[0], v[1], v[2], b3);
if (bb3 == v[1])
v.insert(v.begin() + 1, b3);
else if (bb3 == v[2])
v.insert(v.begin() + 2, b3);
else // Additional fuck-point
{
bb3 = getHeaviest(c, b3, b);
if (bb3 == c)
v.insert(v.begin() + 3, b3);
else
v.insert(v.begin() + 4, b3);
}
v.pb(a1);
}
else if (mx == b3)
{
int mn = getLightest(a1, c, b3);
if (mn == a1)
v.insert(v.begin() + 3, a1);
else
v.pb(a1);
v.pb(b3);
}
else // mx == c
{
int bb3 = getNextLightest(v[0], v[1], v[2], b3);
if (bb3 == v[1])
{
v.insert(v.begin() + 1, b3);
v.insert(v.begin() + 4, a1);
}
else if (bb3 == v[2])
{
v.insert(v.begin() + 2, b3);
v.insert(v.begin() + 4, a1);
}
else // Yet another fuck point
{
int mx2 = getHeaviest(v[0], b3, a1);
if (mx2 == b3)
{
v.insert(v.begin() + 3, b3);
v.insert(v.begin() + 3, a1);
}
else
{
v.insert(v.begin() + 3, a1);
v.insert(v.begin() + 3, b3);
}
}
}
}
}
if (m == b)
{
v[0] = a, v[1] = b, v[2] = c;
int aa1 = getNextLightest(v[0], v[1], v[2], a1);
if (aa1 == v[1])
{
debug("hello");
v.insert(v.begin() + 1, a1);
int mx = getHeaviest(b, c, b2);
if (mx == b2)
v.pb(b2);
else // mx == c
v.insert(v.begin() + 3, b2);
int bb3 = getNextLightest(v[2], v[3], v[4], b3);
if (bb3 == v[2])
v.pb(b3);
else if (bb3 == v[3])
v.insert(v.begin() + 3, b3);
else
v.insert(v.begin() + 4, b3);
}
else // aa1 == v[0] || aa1 == v[2]
{
debug("oi");
if (aa1 == v[0])
{
v.pb(a1);
debug(v.size());
}
else
{
v.insert(v.begin() + 2, a1);
}
int bb2 = getNextLightest(v[1], v[2], v[3], b2);
if (bb2 == v[1])
v.pb(b2);
else if (bb2 == v[2])
v.insert(v.begin() + 2, b2);
else
v.insert(v.begin() + 3, b2);
int bb3 = getNextLightest(v[1], v[2], v[3], b3);
if (bb3 == v[2])
{
v.insert(v.begin() + 2, b3);
}
else if (bb3 == v[3])
{
v.insert(v.begin() + 3, b3);
}
else // One last fuck-point
{
debug("haii");
debug(bb3);
debug(v[1]);
debug(v[2]);
debug(v[3]);
debug(v[4]);
bb3 = getNextLightest(v[2], v[3], v[4], b3);
debug(bb3);
//if (bb3 == v[3])
//{
// debug(a, b, c, a1, b2, b3);
//}
//assert(bb3 != v[3]);
if (bb3 == v[2])
v.pb(b3);
else // bb3 == v[4]
v.insert(v.begin() + 4, b3);
}
}
}
if (m == c)
{
v[0] = a, v[1] = c, v[2] = b;
int aa1 = getNextLightest(v[0], v[1], v[2], a1);
if (aa1 == v[0])
v.pb(a1);
else if (aa1 == v[1])
v.insert(v.begin() + 1, a1);
else
v.insert(v.begin() + 2, a1);
int bb2 = getNextLightest(v[1], v[2], v[3], b2);
if (bb2 == v[1])
v.pb(b2);
else if (bb2 == v[2])
v.insert(v.begin() + 2, b2);
else
v.insert(v.begin() + 3, b2);
int bb3 = getNextLightest(v[2], v[3], v[4], b3);
if (bb3 == v[2])
v.pb(b3);
else if (bb3 == v[3])
v.insert(v.begin() + 3, b3);
else
v.insert(v.begin() + 4, b3);
}
int result[6];
for (int i =0; i< 6; i++)
result[i] = v[i];
answer(result);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |