# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
295665 | peti1234 | Scales (IOI15_scales) | C++17 | 28 ms | 512 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 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];
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() {
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;
}
a++, b++, c++;
if (h==0) ans=getLightest(a, b, c);
if (h==1) ans=getMedian(a, b, c);
if (h==2) ans=getHeaviest(a, b, c);
a--, b--, c--, ans--;
add(a, b, c, h, ans);
}
for (int i=0; i<pos; i++) if (v[i]) ki=i;
for (int i=0; i<f; i++) re[i]=ert[ki][i]+1;
answer(re);
}
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()));
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |