# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
60061 | KieranHorgan | Scales (IOI15_scales) | C++17 | 181 ms | 880 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 <bits/stdc++.h>
using namespace std;
void init(int T) {
/* ... */
}
int gH(vector<int> v, int A, int B, int C) {
--A;--B;--C;
int H = max(v[A], max(v[B], v[C]));
if(v[A]==H) return ++A;
if(v[B]==H) return ++B;
return ++C;
}
int gL(vector<int> v, int A, int B, int C) {
--A;--B;--C;
int L = min(v[A], min(v[B], v[C]));
if(v[A]==L) return ++A;
if(v[B]==L) return ++B;
return ++C;
}
int gM(vector<int> v, int A, int B, int C) {
--A;--B;--C;
int H = max(v[A], max(v[B], v[C]));
if(v[A]==H) {
if(v[B] > v[C]) return ++B;
else return ++C;
}
if(v[B]==H) {
if(v[A] > v[C]) return ++A;
else return ++C;
}
if(v[B] > v[A]) return ++B;
return ++A;
}
int a[7];
void orderCoins() {
/* ... */
// int W[] = {1, 2, 3, 4, 5, 6};
// answer(W);
vector<vector<int>> pos;
vector<vector<int>> nextPos;
vector<int> perm = {1, 2, 3, 4, 5, 6};
do {
pos.push_back(perm);
} while(next_permutation(perm.begin(), perm.end()));
while(pos.size() > 1) {
int best = 0;
int bestVal = 1000;
bool toBreak = 0;
for(int A = 1; A <= 6; A++) {
for(int B = A+1; B <= 6; B++) {
for(int C = B+1; C <= 6; C++) {
int cur, curVal;
cur = 1*10000 + A*1000 + B*100 + C*10 + 0*1;
memset(a, 0, sizeof(a));
for(auto v: pos)
a[gH(v, A, B, C)]++;
curVal = max(a[A], max(a[B], a[C]));
if(curVal < bestVal)
bestVal=curVal, best=cur;
// if(bestVal*(bestVal-1)*(bestVal-1) <= pos.size()) {toBreak=1; break;}
cur = 2*10000 + A*1000 + B*100 + C*10 + 0*1;
memset(a, 0, sizeof(a));
for(auto v: pos)
a[gL(v, A, B, C)]++;
curVal = max(a[A], max(a[B], a[C]));
if(curVal < bestVal)
bestVal=curVal, best=cur;
// if(bestVal*(bestVal-1)*(bestVal-1) <= pos.size()) {toBreak=1; break;}
cur = 3*10000 + A*1000 + B*100 + C*10 + 0*1;
memset(a, 0, sizeof(a));
for(auto v: pos)
a[gM(v, A, B, C)]++;
curVal = max(a[A], max(a[B], a[C]));
if(curVal < bestVal)
bestVal=curVal, best=cur;
// if(bestVal*(bestVal-1)*(bestVal-1) <= pos.size()) {toBreak=1; break;}
}
if(toBreak) break;
}
if(toBreak) break;
}
// cerr << best << ": " << pos.size() << " -> " << bestVal << endl;
int t, A, B, C, D;
D = best%10; best/=10;
C = best%10; best/=10;
B = best%10; best/=10;
A = best%10; best/=10;
t = best%10; best/=10;
int val;
if(t==1) {
val = getHeaviest(A,B,C);
for(auto v: pos)
if(gH(v, A, B, C) == val)
nextPos.push_back(v);
} else if(t==2) {
val = getLightest(A,B,C);
for(auto v: pos)
if(gL(v, A, B, C) == val)
nextPos.push_back(v);
} else if(t==3) {
val = getMedian(A,B,C);
for(auto v: pos)
if(gM(v, A, B, C) == val)
nextPos.push_back(v);
} else {
break;
}
swap(pos, nextPos);
nextPos.clear();
}
int ans[] = {0,0,0,0,0,0};
for(int i = 0; i < 6; i++) {
ans[pos[0][i]-1] = i+1;
}
answer(ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |