# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
520337 | silverfish | Scales (IOI15_scales) | C++17 | 2 ms | 460 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;
#define pb push_back
const int INF = 1000;
int index_of[6];
map<int, int[6]> ans;
int nextl(int a, int b, int c, int d) {
int al = 1;
a--; b--; c--; d--;
if (index_of[a] > index_of[d] || index_of[b] > index_of[d] || index_of[c] > index_of[d])
al = 0;
if (al == 1) {
if (index_of[a] < index_of[b] && index_of[a] < index_of[c])
return a + 1;
if (index_of[b] < index_of[a] && index_of[b] < index_of[c])
return b + 1;
return c + 1;
}
if (index_of[a] > index_of[d]) {
if ((index_of[a] < index_of[b] || index_of[b] < index_of[d]) && (index_of[a] < index_of[c] || index_of[c] < index_of[d]))
return a + 1;
}
if (index_of[b] > index_of[d]) {
if ((index_of[b] < index_of[a] || index_of[a] < index_of[d]) && (index_of[b] < index_of[c] || index_of[c] < index_of[d]))
return b + 1;
}
return c + 1;
}
int mid(int a, int b, int c) {
a--; b--; c--;
if (index_of[b] < index_of[a] && index_of[a] < index_of[c])
return a + 1;
if (index_of[c] < index_of[a] && index_of[a] < index_of[b])
return a + 1;
if (index_of[a] < index_of[b] && index_of[b] < index_of[c])
return b + 1;
if (index_of[c] < index_of[b] && index_of[b] < index_of[a])
return b + 1;
return c + 1;
}
int heavy(int a, int b, int c) {
a--; b--; c--;
if (index_of[a] > index_of[b] && index_of[a] > index_of[c])
return a + 1;
if (index_of[b] > index_of[a] && index_of[b] > index_of[c])
return b + 1;
return c + 1;
}
int light(int a, int b, int c) {
a--; b--; c--;
if (index_of[a] < index_of[b] && index_of[a] < index_of[c])
return a + 1;
if (index_of[b] < index_of[a] && index_of[b] < index_of[c])
return b + 1;
return c + 1;
}
void init(int T) {
vector<int> p = {1, 2, 3, 4, 5, 6};
map<int,int> cnt;
do{
for(int i = 0; i < 6; ++i) index_of[p[i]-1] = i;
vector<int> q;
q.pb(nextl(6,5,1,2));
q.pb(nextl(5,4,6,1));
q.pb(nextl(5,6,2,4));
q.pb(nextl(6,2,1,3));
q.pb(nextl(5,6,4,3));
q.pb(mid(1,2,3));
q.pb(mid(4,5,6));
q.pb(mid(3,4,5));
reverse(q.begin(), q.end());
int mul = 1, cur = 0;
for(int x : q){
cur += mul*x;
mul *= 10;
}
int v = 0;
mul = 1;
for(int i = 0; i < 6; ++i){
ans[cur][i] = p[i];
}
++cnt[cur];
}while(next_permutation(p.begin(), p.end()));
int mx = 0, mxpos;
for(auto [x,c] : cnt){
if(c > mx){
mx = c;
mxpos = x;
}
}
// cout << mx << ' ' << mxpos << '\n';
return;
}
void orderCoins() {
vector<int> q;
q.pb(getNextLightest(6,5,1,2));
q.pb(getNextLightest(5,4,6,1));
q.pb(getNextLightest(5,6,2,4));
q.pb(getNextLightest(6,2,1,3));
q.pb(getNextLightest(5,6,4,3));
q.pb(getMedian(1,2,3));
q.pb(getMedian(4,5,6));
q.pb(getMedian(3,4,5));
reverse(q.begin(), q.end());
int mul = 1, cur = 0;
for(int x : q){
cur += mul*x;
mul *= 10;
}
//cout << cur << '\n';
for(int i = 0; i < 6; ++i) cout << ans[cur][i] << ' ';
cout << '\n';
answer(ans[cur]);
return;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |