# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1055035 | Faisal_Saqib | Scales (IOI15_scales) | C++17 | 0 ms | 0 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.
#pragma once
#include <bits/stdc++.h>
using namespace std;
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
void answer(int C[]);
int getMedian(int A, int B, int C);
int getHeaviest(int A, int B, int C);
int getLightest(int A, int B, int C);
int getNextLightest(int A, int B, int C, int D);
void init(int T)
{
}
void orderCoins()
{
int ap[6];
for(int i=0;i<6;i++)
ap[i]=i+1;
shuffle(ap,ap+6,RNG);
int mx=getHeaviest(ap[0],ap[1],ap[2]);
int mi=getLightest(ap[0],ap[1],ap[2]);
int mx1=getHeaviest(ap[3],ap[4],ap[5]);
int mi1=getLightest(ap[3],ap[4],ap[5]);
int md=ap[0]+ap[1]+ap[2]-mx-mi;
int md1=ap[3]+ap[4]+ap[5]-mx1-mi1;
int a[3];
a[0]=mi;
a[1]=md;
a[2]=mx;
int b[3];
b[0]=mi1;
b[1]=md1;
b[2]=mx1;
int c[6];
int sl=a[0];
int l=a[1];
int pp=0;
bool pos=0;
// for(int i=0;i<3;i++)
// {
// cout<<a[i]<<' ';
// }
// cout<<endl;
// for(int i=0;i<3;i++)
// {
// cout<<b[i]<<' ';
// }
// cout<<endl;
for(int i=0;i<3;i++)
{
// cout<<"Cur "<<sl<<' '<<l<<' '<<b[i]<<endl;
int mid=getMedian(sl,l,b[i]);
if(mid==sl)
{
// it is smaller than
c[pp]=b[i];
pp++;
// b[i] <= sl <= l
}
else if(mid==b[i]){
// sl<= b[i] <= l
c[pp]=sl;
pp++;
sl=b[i];
if(!pos)
{
pos=1;
c[pp]=b[i];
pp++;
sl=l;
l=a[2];
// Saved one query
}
else if(i==0){
int sv=l;
sl=b[i+1];
l=b[i+2];
b[i+2]=sv;
i++;
}
// Optimize
// b[i]<=b[i+1] for sure so just sl = l ,sl=a
}
else if(mid==l){
// We know
// sl<=l
// l<=b[i]<=b[i+1]
// l<=a[2]
c[pp]=sl;
pp++;
sl=l;
l=b[i];
if(!pos)
{
if((i+1)<3)
{
c[pp]=sl;
pp++;
sl=b[i];
l=b[i+1];
b[i+1]=a[2];
// number of queries remain same
}
else{
l=a[2];
i--;
// Wasted one query
}
pos=1;
}
}
}
// cout<<sl<<' '<<l<<' ';
// cout<<pp<<' '<<pp+1<<endl;
c[pp]=sl;
c[pp+1]=l;
if(!pos)
c[pp+2]=a[2];
answer(c);
}