# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
295579 | peti1234 | 저울 (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>
using namespace std;
const int c=722;
vector<int> sz;
int ert[c][6], pos, db, ki, t[3];
bool v[c];
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]=ert[i][a], t[1]=ert[i][b], t[2]=ert[i][c];
sort(t, t+3);
if (a==t[h]) x++;
if (b==t[h]) y++;
if (c==t[h]) 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]=ert[i][a], t[1]=ert[i][b], t[2]=ert[i][c];
sort(t, t+3);
if (t[h]!=ans) v[i]=0, db--;
}
}
void orderCoins() {
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<6; x++) for (int y=x+1; y<6; y++) for (int z=y+1; z<6; 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;
}
if (h==0) v=getLightest(a, b, c);
if (h==1) v=getMedian(a, b, c);
if (h==2) v=getHeaviest(a, b, c);
add(a, b, c, h, v);
}
for (int i=0; i<pos; i++) if (v[i]) ki=i;
vector<int> re;
re.resize(6);
for (int i=0; i<6; i++) re[ert[ki][i]]=i;
answer(re);
}
void init(int t) {
for (int i=0; i<6; i++) sz.push_back(i);
do {
for (int i=0; i<6; i++) ert[pos][i]=sz[i];
pos++;
} while(next_permutation(sz.begin(), sz.end()));
}