# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
125595 | baluteshih | Scales (IOI15_scales) | C++14 | 3 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.
#include "scales.h"
#include <bits/stdc++.h>
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define ET cout << "\n"
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
vector<int> G[6];
void init(int T)
{
}
bool check(int W[])
{
int in[6],tp=0;
queue<int> q;
for(int i=0;i<6;++i)
for(int j:G[i])
++in[j];
for(int i=0;i<6;++i)
if(!in[i]) q.push(i);
while(!q.empty())
{
if(q.size()!=1) return 0;
int tmp=q.front();
q.pop();
W[tp++]=tmp+1;
for(int i:G[tmp])
if(!--in[i])
q.push(i);
}
return 1;
}
void orderCoins()
{
int W[6]={1,2,3,4,5,6};
int x=getLightest(1,2,3),t;
swap(W[0],W[x-1]);
x=getMedian(W[0],W[1],4),W[3]=W[2];
if(x==W[0]) W[2]=W[1],W[1]=W[0],W[0]=4;
else if(x==W[1]) W[2]=4;
else W[2]=W[1],W[1]=4;
x=getNextLightest(W[0],W[1],W[2],W[3]);
if(x==W[1])
t=W[3],W[3]=W[2],W[2]=W[1],W[1]=t;
else if(x==W[2])
t=W[3],W[3]=W[2],W[2]=t;
//W 1~4 is ok
x=getLightest(W[2],5,6);
if(x==W[2])
{
x=getHeaviest(5,6,W[3]);
if(x==5) swap(W[5],W[4]);
else if(x==W[3]) swap(W[3],W[5]);
x=getHeaviest(W[2],W[3],W[4]);
if(x==W[3]) swap(W[3],W[4]);
}
else
{
if(x==W[5]) swap(W[4],W[5]);
x=getNextLightest(W[0],W[1],W[2],W[4]);
if(x==W[0])
{
t=W[4],W[4]=W[3],W[3]=W[2],W[2]=W[1],W[1]=W[0],W[0]=t;
x=getNextLightest(W[0],W[1],W[2],W[5]);
if(x==W[1])
t=W[5],W[5]=W[4],W[4]=W[3],W[3]=W[2],W[2]=W[1],W[1]=t;
else if(x==W[2])
t=W[5],W[5]=W[4],W[4]=W[3],W[3]=W[2],W[2]=t;
else
{
t=W[5],W[5]=W[4],W[4]=W[3],W[3]=t;
x=getNextLightest(W[2],W[4],W[5],W[3]);
if(x==W[2])
t=W[3],W[3]=W[4],W[4]=W[5],W[5]=t;
else if(x==W[5])
swap(W[3],W[4]);
}
}
else if(x==W[1])
{
t=W[4],W[4]=W[3],W[3]=W[2],W[2]=W[1],W[1]=t;
x=getNextLightest(W[1],W[2],W[3],W[5]);
if(x==W[2])
t=W[5],W[5]=W[4],W[4]=W[3],W[3]=W[2],W[2]=t;
else if(x==W[3])
t=W[5],W[5]=W[4],W[4]=W[3],W[3]=t;
else if(getHeaviest(W[0],W[5],W[4])==W[4])
swap(W[4],W[5]);
}
else
{
t=W[4],W[4]=W[3],W[3]=W[2],W[2]=t;
x=getNextLightest(W[2],W[3],W[4],W[5]);
if(x==W[3])
t=W[5],W[5]=W[4],W[4]=W[3],W[3]=t;
else if(x==W[4])
swap(W[4],W[5]);
}
}
return answer(W);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |