# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
276128 | stoyan_malinin | Scales (IOI15_scales) | C++14 | 1 ms | 384 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 "grader.cpp"
#include <set>
#include <vector>
#include <iostream>
using namespace std;
struct Query
{
int type;
set <int> args;
int ans;
Query(){}
Query(int type, set <int> args, int ans)
{
this->type = type;
this->args = args;
this->ans = ans;
}
};
struct QueryKeeper
{
vector <Query> v;
int get(int ind)
{
return v[ind].ans;
}
};
QueryKeeper welko;
int ask(int type, set <int> args)
{
int a, b, c, d;
auto it = args.begin();
a = *it;it++;
b = *it;it++;
c = *it;it++;
if(type==4) d = *it;
int res;
if(type==1) res = getHeaviest(a, b, c);
else if(type==2) res = getLightest(a, b, c);
else if(type==3) res = getMedian(a, b, c);
else if(type==4) res = getNextLightest(a, b, c, d);
welko.v.push_back(Query(type, args, res));
return res;
}
set <int> exclude(set <int> s, vector <int> v)
{
for(int x: v) s.erase(x);
return s;
}
set <int> include(set <int> s, vector <int> v)
{
for(int x: v) s.insert(x);
return s;
}
void init(int T) {
/* ... */
}
void solve4(set <int> s, int *W)
{
vector <int> v;
for(int x: s) v.push_back(x);
int b = ask(1, {v[0], v[1], v[2]});
W[1] = ask(2, exclude(s, {b}));
int med = ask(3, exclude(s, {W[1]}));
int c;
if(v[3]!=W[1]) c = v[3];
else c = *exclude(s, {b, W[1]}).begin();
int a = *exclude(s, {b, c, W[1]}).begin();
if(med==b) W[2] = a, W[3] = b, W[4] = c;
else if(med==a) W[2] = c, W[3] = a, W[4] = b;
else if(med==c) W[2] = a, W[3] = c, W[4] = b;
//cout << a << " " << b << " " << c << '\n';
}
void orderCoins() {
/* ... */
welko.v.clear();
int W[] = {-1, -1, -1, -1, -1, -1};
ask(1, {1, 2, 3});
ask(2, {4, 5, 6});
ask(1, include(exclude({4, 5, 6}, {welko.get(1)}), {welko.get(0)}));
ask(2, include(exclude({1, 2, 3}, {welko.get(0)}), {welko.get(1)}));
W[5] = welko.get(2);
W[0] = welko.get(3);
set <int> rem = exclude({1, 2, 3, 4, 5, 6}, {welko.get(2), welko.get(3)});
solve4(rem, W);
answer(W);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |