Submission #1057309

#TimeUsernameProblemLanguageResultExecution timeMemory
1057309MuhammadSaramScales (IOI15_scales)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;

#define perm array<int, 6>
#define state vector<perm>
#define qu array<int, 4>

map<state,qu> nxt;

int maxx(perm &p,qu &q)
{
	return max(p[q[0]],max(p[q[1]],p[q[2]]));
}

int minn(perm &p,qu &q)
{
	return min(p[q[0]],min(p[q[1]],p[q[2]]));
}

int answer(perm &p,qu q)
{
	if (q[3]==-2)
	{
		int mx=maxx(p,q);
		for (int i=0;i<3;i++)
			if (mx==p[q[i]])
				return q[i];
	}
	else if(q[3]==-1)
	{
		int md=-maxx(p,q)-minn(p,q)+p[q[0]]+p[q[1]]+p[q[2]];
		for (int i=0;i<3;i++)
			if (md==p[q[i]])
				return q[i];
	}
	else if(!q[3])
	{
		int mn=minn(p,q);
		for (int i=0;i<3;i++)
			if (mn==p[q[i]])
				return q[i];
	}
	else
	{
		if (maxx(p,q)<p[q[3]])
		{
			int mn=minn(p,q);
			for (int i=0;i<3;i++)
				if (p[q[i]]==mn)
					return q[i];
		}
		int ans=7;
		for (int i=0;i<3;i++)
			if (p[q[i]]>p[q[3]])
				ans=min(ans,p[q[i]]);
		for (int i=0;i<3;i++)
			if (p[q[i]]==ans)
				return q[i];
	}
}

state whatif(state &v,qu &q,int ans)
{
	state res;
	for (perm p:v)
	{
		if (answer(p,q)==ans)
			res.push_back(p);
	}
	return res;
}

bool solve(state v,int cnt=729)
{
	if (v.size()<=1)
		return 1;
	qu q;
	for (q[0]=0;q[0]<6;q[0]++)
		for (q[1]=q[0]+1;q[1]<6;q[1]++)
			for (q[2]=q[1]+1;q[2]<6;q[2]++)
				for (q[3]=-2;q[3]<6;q[3]++)
				{
					if (q[3]==q[0] or q[3]==q[1] or q[3]==q[2])
						continue;
					state v1=whatif(v,q,q[0]);
					state v2=whatif(v,q,q[1]);
					state v3=whatif(v,q,q[2]);
					int mx=max(max(v2.size(),v3.size()),v1.size());
					if (mx<=cnt/3)
					{
						bool b=solve(v1,cnt/3) && solve(v2,cnt/3) && solve(v3,cnt/3);
						if (b)
						{
							nxt[v]=q;
							return 1;
						}
					}
				}
}

void init(int t)
{
	perm a = {0,1,2,3,4,5};
	state v;
	do
	{
		v.push_back(a);
	}while (next_permutation(a.begin(),a.end()));
	solve(v);
}

void orderCoins()
{
	perm a = {0,1,2,3,4,5};
	state v;
	do
	{
		v.push_back(a);
	}while (next_permutation(a.begin(),a.end()));
	for (int i=0;i<6;i++)
	{
		qu q=nxt[v];
		if (q[3]==-2)
			v=whatif(v,q,getHeaviest(q[0]+1,q[1]+1,q[2]+1)-1);
		else if(q[3]==-1)
			v=whatif(v,q,getMedian(q[0]+1,q[1]+1,q[2]+1)-1);
		else if(!q[3])
			v=whatif(v,q,getLightest(q[0]+1,q[1]+1,q[2]+1)-1);
		else
		{
			int ans=getNextLightest(q[0]+1,q[1]+1,q[2]+1,q[3]+1)-1;
			v=whatif(v,q,ans);
		}
		if (v.size()==1)
			break;
	}
	int ans[6];
	for (int i=0;i<6;i++)
		for (int j=1;j<=6;j++)
			if (v[0][j-1]==i)
				ans[i]=j;
	answer(ans);
}

Compilation message (stderr)

scales.cpp: In function 'bool solve(std::vector<std::array<int, 6> >, int)':
scales.cpp:89:16: warning: conversion from 'long unsigned int' to 'int' may change value [-Wconversion]
   89 |      int mx=max(max(v2.size(),v3.size()),v1.size());
      |             ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
scales.cpp: In function 'void init(int)':
scales.cpp:102:15: warning: unused parameter 't' [-Wunused-parameter]
  102 | void init(int t)
      |           ~~~~^
scales.cpp: In function 'void orderCoins()':
scales.cpp:125:17: error: 'getHeaviest' was not declared in this scope
  125 |    v=whatif(v,q,getHeaviest(q[0]+1,q[1]+1,q[2]+1)-1);
      |                 ^~~~~~~~~~~
scales.cpp:127:17: error: 'getMedian' was not declared in this scope
  127 |    v=whatif(v,q,getMedian(q[0]+1,q[1]+1,q[2]+1)-1);
      |                 ^~~~~~~~~
scales.cpp:129:17: error: 'getLightest' was not declared in this scope
  129 |    v=whatif(v,q,getLightest(q[0]+1,q[1]+1,q[2]+1)-1);
      |                 ^~~~~~~~~~~
scales.cpp:132:12: error: 'getNextLightest' was not declared in this scope
  132 |    int ans=getNextLightest(q[0]+1,q[1]+1,q[2]+1,q[3]+1)-1;
      |            ^~~~~~~~~~~~~~~
scales.cpp:143:9: error: invalid initialization of reference of type 'std::array<int, 6>&' from expression of type 'int [6]'
  143 |  answer(ans);
      |         ^~~
scales.cpp:21:18: note: in passing argument 1 of 'int answer(std::array<int, 6>&, std::array<int, 4>)'
   21 | int answer(perm &p,qu q)
      |                  ^
scales.cpp: In function 'int answer(std::array<int, 6>&, std::array<int, 4>)':
scales.cpp:61:1: warning: control reaches end of non-void function [-Wreturn-type]
   61 | }
      | ^
scales.cpp: In function 'bool solve(std::vector<std::array<int, 6> >, int)':
scales.cpp:100:1: warning: control reaches end of non-void function [-Wreturn-type]
  100 | }
      | ^