# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
794122 | prvocislo | 저울 (IOI15_scales) | C++17 | 6 ms | 852 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "scales.h"
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int getMedian(int A, int B, int C);
int getHeaviest(int A, int B, int C);
int getLightest(int A, int B, int C);
int getNextLightest(int A, int B, int C, int D);
void answer(int C[]);
const int k = 6;
struct question { int typ; vector<int> c; };
int ask(question q)
{
if (q.typ == 0) return getLightest(q.c[0] + 1, q.c[1] + 1, q.c[2] + 1) - 1;
if (q.typ == 1) return getMedian(q.c[0] + 1, q.c[1] + 1, q.c[2] + 1) - 1;
if (q.typ == 2) return getHeaviest(q.c[0] + 1, q.c[1] + 1, q.c[2] + 1) - 1;
return getNextLightest(q.c[0] + 1, q.c[1] + 1, q.c[2] + 1, q.c[3] + 1) - 1;
}
struct permutacia
{
vector<int> p;
int ans(const question &q)
{
if (q.typ == 3)
{
for (int i = 0; i < k; i++) if (p[i] == q.c.back())
for (int j = i + 1; j < k; j++) if (count(q.c.begin(), q.c.end(), p[j])) return p[j];
for (int j = 0; j < k; j++) if (count(q.c.begin(), q.c.end(), p[j])) return p[j];
}
vector<int> v;
int cnt = 0;
for (int j = 0; j < k; j++)
{
if (count(q.c.begin(), q.c.end(), p[j])) cnt++;
if (cnt == q.typ + 1) return p[j];
}
}
};
struct node
{
vector<permutacia> can;
int id; vector<int> sons;
node() { id = 0, sons.resize(6, -1); }
} tr[2000];
int cnt = 1;
vector<question> v; // 75 otazok
void fill(int vr)
{
if (tr[vr].can.size() == 1) return;
else if (tr[vr].can.size() == 720) tr[vr].id = 0; // opytame sa na najlahsi z prvych troch
else if (tr[vr].can.size() == 120) tr[vr].id = 116; // opytame sa na najtazsi z poslednych troch
else
{
int best = tr[vr].can.size();
for (int q = 0; q < v.size(); q++)
{
vector<int> num(k, 0);
for (permutacia& i : tr[vr].can) num[i.ans(v[q])]++;
int maxi = *max_element(num.begin(), num.end());
if (maxi < best) best = maxi, tr[vr].id = q;
if (best == (tr[vr].can.size() + 2) / 3) break;
}
}
vector<vector<permutacia> > syn(k);
for (permutacia& i : tr[vr].can) syn[i.ans(v[tr[vr].id])].push_back(i);
for (int i = 0; i < k; i++) if (syn[i].size())
{
tr[cnt].can = syn[i], tr[vr].sons[i] = cnt;
fill(cnt++);
}
}
void init(int T)
{
permutacia p;
for (int i = 0; i < k; i++) p.p.push_back(i);
tr[0].can.push_back(p);
while (next_permutation(p.p.begin(), p.p.end())) tr[0].can.push_back(p);
for (int a = 0; a < k; a++) for (int b = a + 1; b < k; b++) for (int c = b + 1; c < k; c++)
{
for (int typ = 0; typ < 3; typ++) v.push_back({ typ, {a, b, c} });
for (int d = 0; d < k; d++) if (a != d && b != d && c != d) v.push_back({ 3, {a, b, c, d} });
}
fill(0);
}
int ans[k];
void orderCoins()
{
int vr = 0;
while (tr[vr].can.size() > 1)
{
vr = tr[vr].sons[ask(v[tr[vr].id])];
}
for (int i = 0; i < k; i++) ans[i] = tr[vr].can[0].p[i] + 1;
answer(ans);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |