# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
788806 | fatemetmhr | 저울 (IOI15_scales) | C++17 | 33 ms | 384 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.
// ~ Be Name Khoda ~ //
#include "scales.h"
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops,Ofast")
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 1e6 + 10;
const int maxn5 = 5e5 + 10;
const int maxnt = 1.2e6 + 10;
const int maxn3 = 1e3 + 10;
const int mod = 1e9 + 7;
const ll inf = 1e18;
/*
0 -> getLightest()
1 -> getMedian()
2 -> getHeaviest()
getNextLightest();
*/
struct Comp{
int x[3], cnt[3][3];
int find_order(int a){
if(a == x[0])
return 0;
if(a == x[1])
return 1;
if(a == x[2])
return 2;
return -1;
}
} op1[70];
struct BS{
int x[3], y[3], cnt[3][3];
int find_order(int a){
if(a == x[0])
return 0;
if(a == x[1])
return 1;
if(a == x[2])
return 2;
return -1;
}
} op2[70];
int pt1 = 0, pt2 = 0;
struct perm{
int a[6];
int get_op1(int ty, Comp c){
int cnt = 0;
for(int i = 0; i < 6; i++){
if(c.find_order(a[i]) != -1)
cnt++;
if(cnt - 1 == ty)
return c.find_order(a[i]);
}
return -1;
}
int get_op2(int ty, BS c){
for(int i = 0; i < 6; i++) if(a[i] == c.y[ty]){
for(int j = i + 1; ; j = (j + 1) % 6)
if(c.find_order(a[j]) != -1)
return c.find_order(a[j]);
}
return -1;
}
} av[1000];
bool rem[1000];
void init(int T) {
int a[6];
for(int i = 0; i < 6; i++)
a[i] = i + 1;
for(int i = 0; i < 720; i++){
for(int j = 0; j < 6; j++)
av[i].a[j] = a[j];
next_permutation(a, a + 6);
}
for(int i = 1; i <= 6; i++)
for(int j = i + 1; j <= 6; j++)
for(int k = j + 1; k <= 6; k++){
op1[pt1].x[0] = i;
op1[pt1].x[1] = j;
op1[pt1].x[2] = k;
pt1++;
op2[pt2].x[0] = i;
op2[pt2].x[1] = j;
op2[pt2].x[2] = k;
int ind = 0;
for(int x = 1; x <= 6; x++) if(x != i && x != j && x != k)
op2[pt2].y[ind++] = x;
pt2++;
}
}
void orderCoins() {
memset(rem, false, sizeof rem);
int have = 720;
while(have > 1){
pair <int, pair<int, int>> mnid = {0, {0, 0}};
int mn = 730;
for(int i = 0; i < pt1; i++){
memset(op1[i].cnt, 0, sizeof op1[i].cnt);
for(int j = 0; j < 720; j++) if(!rem[j]){
op1[i].cnt[0][av[j].get_op1(0, op1[i])]++;
op1[i].cnt[1][av[j].get_op1(1, op1[i])]++;
op1[i].cnt[2][av[j].get_op1(2, op1[i])]++;
}
for(int j = 0; j < 3; j++){
int val = max({op1[i].cnt[j][0], op1[i].cnt[j][1], op1[i].cnt[j][2]});
//cout << "he? " << i << ' ' << j << ' ' << mn << ' ' << val << endl;
if(max({op1[i].cnt[j][0], op1[i].cnt[j][1], op1[i].cnt[j][2]}) < mn){
mn = max({op1[i].cnt[j][0], op1[i].cnt[j][1], op1[i].cnt[j][2]});
mnid = {0, {i, j}};
}
}
}
for(int i = 0; i < pt1; i++){
memset(op2[i].cnt, 0, sizeof op2[i].cnt);
for(int j = 0; j < 720; j++) if(!rem[j]){
op2[i].cnt[0][av[j].get_op2(0, op2[i])]++;
op2[i].cnt[1][av[j].get_op2(1, op2[i])]++;
op2[i].cnt[2][av[j].get_op2(2, op2[i])]++;
}
for(int j = 0; j < 3; j++)
if(max({op2[i].cnt[j][0], op2[i].cnt[j][1], op2[i].cnt[j][2]}) <= mn){
mn = max({op2[i].cnt[j][0], op2[i].cnt[j][1], op2[i].cnt[j][2]});
mnid = {1, {i, j}};
}
}
int ans;
if(mnid.fi == 0){
int x;
if(mnid.se.se == 0)
x = getLightest(op1[mnid.se.fi].x[0], op1[mnid.se.fi].x[1], op1[mnid.se.fi].x[2]);
if(mnid.se.se == 1)
x = getMedian(op1[mnid.se.fi].x[0], op1[mnid.se.fi].x[1], op1[mnid.se.fi].x[2]);
if(mnid.se.se == 2)
x = getHeaviest(op1[mnid.se.fi].x[0], op1[mnid.se.fi].x[1], op1[mnid.se.fi].x[2]);
ans = op1[mnid.se.fi].find_order(x);
for(int i = 0; i < 720; i++)
if(!rem[i] && av[i].get_op1(mnid.se.se, op1[mnid.se.fi]) != ans){
rem[i] = true;
have--;
}
/*
cout << "found out op1 " << mn << ' ' << mnid.fi << ' ' << mnid.se.fi << ' ' << mnid.se.se << endl;
for(int i = 0; i < 3; i++)
cout << op1[mnid.se.fi].x[i] << ' ';
cout << endl;
cout << av[0].get_op1(2, op1[0]) << endl;
cout << op1[0].cnt[0][0] << ' ' << op1[0].cnt[0][1] << ' ' << op1[0].cnt[0][2] << endl;
*/
}
else{
int x = getNextLightest(op2[mnid.se.fi].x[0], op2[mnid.se.fi].x[1], op2[mnid.se.fi].x[2], op2[mnid.se.fi].y[mnid.se.se]);
ans = op2[mnid.se.fi].find_order(x);
for(int i = 0; i < 720; i++)
if(!rem[i] && av[i].get_op2(mnid.se.se, op2[mnid.se.fi]) != ans){
rem[i] = true;
have--;
}
/*
cout << "found out op2 " << mn << ' ' << mnid.fi << ' ' << mnid.se.fi << ' ' << mnid.se.se << endl;
for(int i = 0; i < 3; i++)
cout << op2[mnid.se.fi].x[i] << ' ';
cout << op2[mnid.se.fi].y[mnid.se.se] << endl;
*/
}
//cout << "ya " << have << endl;
}
int ret[6];
for(int i = 0; i < 720; i++) if(!rem[i])
for(int j = 0; j < 6; j++)
ret[j] = av[i].a[j];
answer(ret);
return;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |