# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1031441 | Dan4Life | Scales (IOI15_scales) | C++17 | 1 ms | 348 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 set_arr(int a, int b, int c, int d, int e, int f){
W[1]=a,W[2]=b,W[3]=c,W[4]=d,W[5]=e,W[6]=f;
}
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); upd_vals();
if(getMin(A,D,E)!=A) set_arr(D,E,F,A,B,C), upd_vals();
int nx = getNext(A,B,C,D), checklst3=0;
if(nx!=A){
if(nx==C) set_arr(A,B,D,C,E,F), upd_vals(), checklst3=1;
else{
set_arr(A,D,B,C,E,F), upd_vals(), checklst3=1;
int bigger = getMax(A,C,E);
if(bigger==C) set_arr(A,B,E,F,C,D), upd_vals();
}
}
if(checklst3){
int med = getMiddle(D,E,F);
if(med==E) set_arr(A,B,C,D,E,F);
else if(med==F) set_arr(A,B,C,E,F,D);
else set_arr(A,B,C,E,D,F);
upd_vals();
}
int ans[] = {A,B,C,D,E,F}; answer(ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |