Submission #1031441

#TimeUsernameProblemLanguageResultExecution timeMemory
1031441Dan4LifeScales (IOI15_scales)C++17
55.56 / 100
1 ms348 KiB
#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)

scales.cpp: In function 'void init(int)':
scales.cpp:57:15: warning: unused parameter 'T' [-Wunused-parameter]
   57 | void init(int T) {}
      |           ~~~~^
scales.cpp: In function 'void sort3in2(int, int, int)':
scales.cpp:60:6: warning: declaration of 'A' shadows a global declaration [-Wshadow]
   60 |  int A = W[a], B = W[b], C = W[c];
      |      ^
scales.cpp:13:5: note: shadowed declaration is here
   13 | int A,B,C,D,E,F;
      |     ^
scales.cpp:60:16: warning: declaration of 'B' shadows a global declaration [-Wshadow]
   60 |  int A = W[a], B = W[b], C = W[c];
      |                ^
scales.cpp:13:7: note: shadowed declaration is here
   13 | int A,B,C,D,E,F;
      |       ^
scales.cpp:60:26: warning: declaration of 'C' shadows a global declaration [-Wshadow]
   60 |  int A = W[a], B = W[b], C = W[c];
      |                          ^
scales.cpp:13:9: note: shadowed declaration is here
   13 | int A,B,C,D,E,F;
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...