# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
122635 | win11905 | Scales (IOI15_scales) | C++11 | 13 ms | 504 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>
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
vector<pair<int, vector<int> > > que;
vector<vector<int> > perm;
int ids[] = {0, 1, 1, 1, 5, 4, -1, 5, 4, -1, 3, 3, -1, 16, 16, 41, 29, 40, -1, -1, -1, -1, 16, 16, 41, 32, 40, -1, -1, -1, -1, 30, 39, -1, 33, 39, -1, -1, -1, -1, 24, 29, -1, 88, 0, -1, 86, 86, 7, 88, 86, 3, 107, 96, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 85, 0, -1, 21, 29, -1, 89, 89, 6, 85, 85, 3, 107, 96, 7, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 107, 86, 4, 88, 88, 6, -1, -1, -1, 107, 89, 4, 85, 85, 6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 52, 52, 52, 50, 50, -1, -1, -1, -1, 55, 115, 24, 52, -1, -1, -1, -1, -1, 52, 58, 104, 52, 58, 115, 55, 58, -1, 65, 104, 34, 65, 18, 21, 52, 50, -1, 75, 34, 18, 75, 24, 18, 55, 54, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 58, 111, 21, 52, -1, -1, -1, -1, -1, 52, 52, 52, 50, 50, -1, -1, -1, -1, 52, 55, 100, 52, 55, 111, 55, 58, -1, 68, 100, 31, 68, 100, 18, 52, 50, -1, 75, 31, 18, 75, 21, 18, 55, 54, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 65, 34, 24, 65, 18, 21, 52, 51, -1, 75, 93, 34, 75, 93, 24, 55, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 68, 31, 21, 68, 18, 21, 52, 51, -1, 75, 93, 31, 75, 93, 21, 55, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 63, 85, 54, 63, 68, 96, 63, 34, 96, 58, 107, -1, 58, 107, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 20, 96, 96, 107, 55, 55, 107, 64, 64, 84, 64, 54, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 85, 75, 24, 16, 75, 75, 89, 65, 24, 85, 75, 24, 65, 7, 75, 89, 55, 89, 51, 107, 89, 50, 107, -1, -1, -1, 30, 107, 107, 96, 65, 65, 96, 54, 54, 58, 24, 24, 63, 96, 58, -1, 58, 89, 84, 54, 64, 58, 107, -1, -1, -1, -1, 18, 52, 18, 86, 54, 52, 52, 30, 51, 52, 18, 18, 86, 64, 52, 52, 20, 51, -1, 85, 68, 52, 107, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 19, 96, 96, 107, 58, 58, 107, 64, 64, 64, 84, 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 85, 63, 53, -1, 63, 96, -1, 63, 96, 55, 107, -1, 55, 107, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 21, 75, 21, 16, 75, 75, 86, 68, 24, 21, 75, 21, 68, 6, 75, 86, 58, 86, 50, 107, 86, 51, 107, -1, -1, -1, 29, 107, 107, 96, 68, 68, 96, 54, 54, 89, 16, 89, 96, 68, 68, 96, 54, 54, 54, 84, 63, 55, 107, -1, -1, -1, -1, 18, 52, 18, 89, 54, 52, 30, 52, 51, 52, 18, 18, 89, 64, 52, 20, 52, 51, 50, 85, 64, 52, 107, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 58, 24, 96, 51, 58, 29, 58, 50, 58, 24, 24, 64, 96, 58, -1, 58, 89, 85, 53, 63, 58, 107, -1, -1, -1, -1, 29, 107, 107, 75, 86, 75, 86, 51, 51, 96, 19, 96, 75, 86, 75, 86, 51, 51, -1, 84, 68, 52, 107, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 21, 55, 21, 96, 51, 55, 30, 55, 50, 55, 21, 21, 96, 64, 55, 17, 55, 50, 53, 85, 64, 55, 107, -1, -1, -1, -1, 29, 107, 107, 89, 75, 75, 89, 51, 51, 96, 19, 96, 89, 75, 75, 89, 51, 51, 51, 84, 63, 52, 107, 0};
int mx = 0;
int zzz;
int dfs(int u, vector<int> vec, int lv) {
if(vec.size() == 1) return vec[0];
mx = max(mx, u);
for(int ii = ids[u];;) {
auto& z = que[ii];
vector<int> Mp[6];
int abc;
if(z.x == 0) abc = getHeaviest(z.y[0]+1, z.y[1]+1, z.y[2]+1);
if(z.x == 1) abc = getLightest(z.y[0]+1, z.y[1]+1, z.y[2]+1);
if(z.x == 2) abc = getMedian(z.y[0]+1, z.y[1]+1, z.y[2]+1);
if(z.x == 3) abc = getNextLightest(z.y[0]+1, z.y[1]+1, z.y[2]+1, z.y[3]+1);
for(int v : vec) {
vector<pii> val;
for(int i = 0; i < 3; ++i) val.emplace_back(perm[v][z.y[i]], z.y[i]);
sort(val.begin(), val.end());
if(z.x == 0)
Mp[val[2].y].emplace_back(v);
else if(z.x == 1)
Mp[val[0].y].emplace_back(v);
else if(z.x == 2)
Mp[val[1].y].emplace_back(v);
else for(int i = 2; i >= -1; --i) {
if(i == -1) Mp[val[0].y].emplace_back(v);
else if(val[i].x > perm[v][z.y[3]]) {
Mp[val[i].y].emplace_back(v);
break;
}
}
}
int step = 0;
for(int i = 0; i < 6; ++i) if(Mp[i].size()) {
step++;
if(i == abc-1)
return dfs(u*3 + step, Mp[i], lv / 3);
}
}
return false;
}
int nth = 6;
void init(int T) {
for(int i = 0; i < (1 << nth); ++i) {
vector<int> vec;
for(int j = 0; j < nth; ++j) if(i >> j & 1)
vec.emplace_back(j);
if(vec.size() == 3)
for(int j = 0; j < 3; ++j) que.emplace_back(j, vec);
if(vec.size() == 4) {
for(int i = 0; i < 4; ++i) {
vector<int> ret;
for(int j = 0; j < 4; ++j) if(i != j) ret.emplace_back(vec[j]);
ret.emplace_back(vec[i]);
que.emplace_back(3, ret);
}
}
}
vector<int> now;
for(int i = 0; i < nth; ++i) now.emplace_back(i+1);
do {
perm.emplace_back(now);
} while(next_permutation(now.begin(), now.end()));
}
void orderCoins() {
int* ans = new int[6];
vector<int> zz;
for(int i = 0; i < perm.size(); ++i) zz.emplace_back(i);
int k = dfs(0, zz, 2187);
for(int i = 0; i < 6; ++i) ans[perm[k][i]-1] = i+1;
answer(ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |