# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
158380 | johutha | Scales (IOI15_scales) | C++14 | 381 ms | 524 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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
enum optype
{
Lightest, Median, Heaviest, Next,
};
void init(int t)
{
}
bool works(string input, optype op, int res, int a, int b, int c, int d = -1)
{
vector<int> srtd;
int dpos = -1;
for (int i = 0; i < 6; i++)
{
int nm = input[i] - '0';
if (nm == d) dpos = srtd.size();
if (nm == a || nm == b || nm == c || nm == d) srtd.push_back(nm);
}
if (op == Lightest) return srtd[0] == res;
if (op == Median) return srtd[1] == res;
if (op == Heaviest) return srtd[2] == res;
return srtd[(dpos + 1) % 4] == res;
}
void orderCoins()
{
vector<string> allst;
string st = "123456";
do
{
allst.push_back(st);
} while (next_permutation(st.begin(), st.end()));
while (allst.size() > 1)
{
vector<int> lbst;
int lbv = 1000;
for (int i1 = 1; i1 < 7; i1++)
{
for (int i2 = 1; i2 < i1; i2++)
{
for (int i3 = 1; i3 < i2; i3++)
{
int s1 = 0;
int s2 = 0;
int s3 = 0;
for (string s : allst)
{
if (works(s, Lightest, i1, i1, i2, i3)) s1++;
else if (works(s, Lightest, i2, i1, i2, i3)) s2++;
else s3++;
}
if (max(s1, max(s2, s3)) < lbv)
{
lbv = max(s1, max(s2, s3));
lbst = {i1, i2, i3};
}
}
}
}
vector<int> mbst;
int mbv = 1000;
for (int i1 = 1; i1 < 7; i1++)
{
for (int i2 = 1; i2 < i1; i2++)
{
for (int i3 = 1; i3 < i2; i3++)
{
int s1 = 0;
int s2 = 0;
int s3 = 0;
for (string s : allst)
{
if (works(s, Median, i1, i1, i2, i3)) s1++;
else if (works(s, Median, i2, i1, i2, i3)) s2++;
else s3++;
}
if (max(s1, max(s2, s3)) < mbv)
{
mbv = max(s1, max(s2, s3));
mbst = {i1, i2, i3};
}
}
}
}
vector<int> hbst;
int hbv = 1000;
for (int i1 = 1; i1 < 7; i1++)
{
for (int i2 = 1; i2 < i1; i2++)
{
for (int i3 = 1; i3 < i2; i3++)
{
int s1 = 0;
int s2 = 0;
int s3 = 0;
for (string s : allst)
{
if (works(s, Heaviest, i1, i1, i2, i3)) s1++;
else if (works(s, Heaviest, i2, i1, i2, i3)) s2++;
else s3++;
}
if (max(s1, max(s2, s3)) < hbv)
{
hbv = max(s1, max(s2, s3));
hbst = {i1, i2, i3};
}
}
}
}
vector<string> nbt;
if (lbv < mbv && lbv < hbv)
{
int r = getLightest(lbst[0], lbst[1], lbst[2]);
for (string s : allst)
{
if (works(s, Lightest, r, lbst[0], lbst[1], lbst[2])) nbt.push_back(s);
}
}
else if (mbv < hbv)
{
int r = getMedian(mbst[0], mbst[1], mbst[2]);
for (string s : allst)
{
if (works(s, Median, r, mbst[0], mbst[1], mbst[2])) nbt.push_back(s);
}
}
else
{
int r = getHeaviest(hbst[0], hbst[1], hbst[2]);
for (string s : allst)
{
if (works(s, Heaviest, r, hbst[0], hbst[1], hbst[2])) nbt.push_back(s);
}
}
allst = nbt;
}
vector<int> res;
for (int i = 0; i < 6; i++)
{
res.push_back(allst[0][i] - '0');
}
answer(res.data());
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |