# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
295642 | peti1234 | Scales (IOI15_scales) | C++17 | 0 ms | 0 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>
#include "scales.h"
using namespace std;
const int cc=722, f=6;
vector<int> sz;
int ert[cc][f], inv[cc][f], pos, db, ki, t[3], re[f], q;
bool v[cc];
/*
int getLightest(int a, int b, int c) {
cout << "kerdes " << a << " " << b << " " << c << " " << 0 << "\n";
int x; cin >> x;
return x;
}
int getMedian(int a, int b, int c) {
cout << "kerdes " << a << " " << b << " " << c << " " << 1 << "\n";
int x; cin >> x;
return x;
}
int getHeaviest(int a, int b, int c) {
cout << "kerdes " << a << " " << b << " " << c << " " << 2 << "\n";
int x; cin >> x;
return x;
}
void answer(int w[]) {
cout << "valasz\n";
for (int i=0; i<f; i++) cout << w[i] << " ";
cout << "\n";
}
*/
int ask(int a, int b, int c, int h) {
int x=0, y=0, z=0;
for (int i=0; i<pos; i++) if (v[i]) {
t[0]=inv[i][a], t[1]=inv[i][b], t[2]=inv[i][c];
//cout << i << " " << t[0] << " " << t[1] << " " << t[2] << endl;
//cout << ert[i][0] << endl;
sort(t, t+3), q=ert[i][t[h]];
if (a==q) x++;
if (b==q) y++;
if (c==q) z++;
}
return max({x, y, z});
}
void add(int a, int b, int c, int h, int ans) {
for (int i=0; i<pos; i++) if (v[i]) {
t[0]=inv[i][a], t[1]=inv[i][b], t[2]=inv[i][c];
sort(t, t+3);
if (ert[i][t[h]]!=ans) v[i]=0, db--;
}
}
void orderCoins() {
aswer(ert[0]);
return;
db=0, ki=0;
for (int i=0; i<pos; i++) v[i]=1, db++;
while(db>1) {
int a=1, b=1, c=1, h=0, mini=db, ans=0;
for (int x=0; x<f; x++) for (int y=x+1; y<f; y++) for (int z=y+1; z<f; z++) for (int e=0; e<3; e++) {
int p=ask(x, y, z, e);
if (p<mini) mini=p, a=x, b=y, c=z, h=e;
}
//cout << "cel " << db << " " << mini << endl;
if (h==0) ans=getLightest(a, b, c);
if (h==1) ans=getMedian(a, b, c);
if (h==2) ans=getHeaviest(a, b, c);
add(a, b, c, h, ans);
}
for (int i=0; i<pos; i++) if (v[i]) ki=i;
answer(ert[ki]);
}
void init(int w) {
for (int i=0; i<f; i++) sz.push_back(i);
do {
for (int i=0; i<f; i++) inv[pos][i]=sz[i], ert[pos][sz[i]]=i;
pos++;
} while(next_permutation(sz.begin(), sz.end()));
}