# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1031411 | Dan4Life | Scales (IOI15_scales) | C++17 | 1 ms | 444 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
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
using ll = long long;
using vi = vector<int>;
using ar2 = array<int,2>;
int W[] = {0, 1, 2, 3, 4, 5, 6};
int A,B,C,D,E,F;
int getInd(int x){
for(int i = 1; i <= 6; i++)
if(W[i]==x) return i;
return 0;
}
int getMx[10][10][10];
int getMax(int a, int b, int c){
if(a>b)swap(a,b);
if(b>c)swap(b,c);
if(a>b)swap(a,b);
if(getMx[a][b][c]) return getMx[a][b][c];
return getMx[a][b][c]=getHeaviest(a,b,c);
}
int getMn[10][10][10];
int getMin(int a, int b, int c){
if(a>b)swap(a,b);
if(b>c)swap(b,c);
if(a>b)swap(a,b);
if(getMn[a][b][c]) return getMn[a][b][c];
return getMn[a][b][c]=getLightest(a,b,c);
}
int getMed[10][10][10];
int getMiddle(int a, int b, int c){
if(a>b)swap(a,b);
if(b>c)swap(b,c);
if(a>b)swap(a,b);
if(getMed[a][b][c]) return getMed[a][b][c];
return getMed[a][b][c]=getMedian(a,b,c);
}
int getNxt[10][10][10][10];
int getNext(int a, int b, int c, int d){
if(a>b)swap(a,b);
if(b>c)swap(b,c);
if(a>b)swap(a,b);
if(getNxt[a][b][c][d]) return getNxt[a][b][c][d];
return getNxt[a][b][c][d]=getNextLightest(a,b,c,d);
}
void init(int T) {}
void sort3in2(int a, int b, int c){
int A = W[a], B = W[b], C = W[c];
int med = getMiddle(W[a],W[b],W[c]);
int mx = getMax(W[a],W[b],W[c]);
int mn = med^mx^A^B^C;
W[a]=mn;W[b]=med;W[c]=mx;
}
void upd_vals(){
A=W[1],B=W[2],C=W[3],D=W[4],E=W[5],F=W[6];
}
void orderCoins() {
memset(getMx,0,sizeof(getMx));
memset(getMn,0,sizeof(getMn));
memset(getMed,0,sizeof(getMed));
memset(getNxt,0,sizeof(getNxt));
for(int i = 1; i <= 6; i++) W[i]=i;
sort3in2(1,2,3); sort3in2(4,5,6); // a<b<c d<e<f
upd_vals();
if(getMin(A,D,E)!=A){
W[1]=D,W[2]=E,W[3]=F;
W[4]=A,W[5]=B,W[6]=C;
}
upd_vals();
int nx = getNext(A,B,C,D), checklst3=0;
if(nx==A){
int med = getMiddle(C,D,E);
if(med!=D) W[1]=D,W[2]=A,W[3]=B,W[4]=C, checklst3=1;
}
else{
if(nx==C) W[1]=A,W[2]=B,W[3]=D;
else W[1]=A,W[2]=D,W[3]=B;
W[4]=C; checklst3=1;
}
upd_vals();
if(checklst3){
int med = getMiddle(W[4],W[5],W[6]);
C=W[4],E=W[5],F=W[6];
if(med==E) W[4]=C,W[5]=E,W[6]=F;
else if(med==F) W[4]=E,W[5]=F,W[6]=C;
else W[4]=E,W[5]=C,W[6]=F;
}
int ans[] = {W[1],W[2],W[3],W[4],W[5],W[6]}; answer(ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |