# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
70644 | Navick | Scales (IOI15_scales) | C++17 | 4 ms | 628 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>
#define F first
#define S second
#define pb push_back
#define pii pair<int, int>
using namespace std;
typedef long long ll;
const int maxN = 6;
vector <int> t;
int ans[maxN];
void init(int T) {
/* ... */
}
void orderCoins() {
int a = getHeaviest(1, 2, 3);
int b = getHeaviest(4, 5, 6);
t.resize(0);
for (int i=4; i<=6; i++)
if(i != b) t.pb(i);
int a1 = getHeaviest(a, t[0], t[1]);
if(a1 >= 4)
{
ans[0] = b;
ans[1] = a1;
int c = 15;
for (int i=4; i<=6; i++)
if(i == b || i == a1) c -= i;
t.resize(0);
for (int i=1; i<=3; i++)
if(i != a) t.pb(i);
int g = getHeaviest(c, t[0], t[1]);
if(g == c)
{
ans[3] = getLightest(ans[0], a, c);
ans[2] = a + c - ans[3];
ans[5] = getLightest(ans[0], t[0], t[1]);
ans[4] = t[0] + t[1] - ans[5];
reverse(ans, ans + maxN);
answer(ans);
return ;
}else
{
ans[2] = a;
ans[3] = g;
int oth = t[0] + t[1] - g;
ans[5] = getLightest(ans[0], c, oth);
ans[4] = oth + c - ans[5];
reverse(ans, ans + maxN);
answer(ans);
return ;
}
}else
{
int c = -1;
for (int i=1; i<=3; i++)
if(i != a) c = i;
int md = getMedian(a, b, c);
if(md != c)
{
ans[0] = a + b - md;
ans[1] = a + b - ans[0];
t.resize(0);
for (int i=1; i<=6; i++)
if(i != a && i != b) t.pb(i);
int c1 = getHeaviest(t[0], t[1], t[2]);
int r = t[3];
t.resize(0);
for (int i=1; i<=6; i++)
if(i != a && i != b && i != c1) t.pb(i);
int c2 = getLightest(t[0], t[1], t[2]);
if(c2 != r)
{
ans[5] = c2;
t.resize(0);
for (int i=1; i<=6; i++)
if(i != a && i != b && i != c2 && i != r && i != c1) t.pb(i);
int md2 = getMedian(t[0], c1, r);
if(md2 == c1) ans[2] = r, ans[3] = c1, ans[4] = t[0];
else if(md2 == t[0]) ans[2] = c1, ans[3] = t[0], ans[4] = r;
else ans[2] = c1, ans[3] = r, ans[4] = t[0];
}else
{
ans[5] = c2;
ans[2] = c1;
t.resize(0);
for (int i=1; i<=6; i++)
if(i != a && i != b && i != c1 && i != c2) t.pb(i);
int g = getLightest(c1, t[0], t[1]);
ans[4] = g;
ans[3] = t[0] + t[1] - g;
}
reverse(ans, ans + maxN);
answer(ans);
}else
{
ans[0] = a;
t.resize(0);
for (int i=1; i<=3; i++)
if(i != a) t.pb(i);
ans[1] = getMedian(a, t[0], t[1]);
int r = t[0] + t[1] - ans[1];
t.resize(0);
for (int i=4; i<=6; i++)
if(i != b) t.pb(i);
int c2 = getLightest(r, t[0], t[1]);
ans[5] = c2;
if(c2 == r)
{
ans[4] = getLightest(b, t[0], t[1]);
ans[3] = t[0] + t[1] - ans[4];
ans[2] = b;
}else
{
int oth = t[0] + t[1] - c2;
int md2 = getMedian(b, r, oth);
if(md2 == b) ans[2] = r, ans[3] = b, ans[4] = oth;
else if(md2 == r) ans[2] = b, ans[3] = r, ans[4] = oth;
else ans[2] = b, ans[3] = oth, ans[4] = r;
}
reverse(ans, ans + maxN);
answer(ans);
return ;
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |