Submission #701810

# Submission time Handle Problem Language Result Execution time Memory
701810 2023-02-22T06:59:05 Z Etherite Speedrun (RMI21_speedrun) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "speedrun.h"

using namespace std;

void dfsHint(int curr, int par, vector<vector<int>> &adjHint, vector<int> &path)
{
	path.push_back(curr);
	for(int i = 0; i < 10; i++) // set in big-endian
	{
		if(par & (1 << i)) setHint(curr, i + 1, 1);
		else setHint(curr, i + 1, 0);
	}
	for(int next : adjHint[curr])
	{
		if(next == par) continue;
		dfsHint(next, curr, adjHint, path);
	}
}

void assignHints(int subtask, int N, int A[], int B[]) 
{
	setHintLen(20);
	vector<vector<int>> adjHint(N + 1);
	for(int i = 1; i < N; i++)
	{
		adjHint[A[i]].push_back(B[i]);
		adjHint[B[i]].push_back(A[i]);
	}
	for(int i = 1; i <= N; i++) sort(adjHint[i].begin(), adjHint[i].end());
	vector<int> path;
	dfsHint(1, 0, adjHint, path);
	for(int i = 0; i < path.size() - 1; i++)
	{
		int child = path[i + 1];
		for(int i = 10; i < 20; i++) // set in big-endian
		{
			if(child & (1 << (i - 10))) setHint(path[i], i + 1, 1);
			else setHint(path[i], i + 1, 0);
		}
	}
}

int next;

int dfs(int curr, int toTry) // returns next value to try
{
	int par = 0, child = 0;
	for(int i = 0; i < 10; i++) par += getHint(i + 1) * (1 << i);
	for(int i = 10; i < 20; i++) child += getHint(i + 1) * (1 << (i - 10));

	if(toTry == 0) toTry = child;
	if(toTry == 0) return 0;
	
	if(goTo(toTry)) return dfs(toTry, 0);
	else 
	{
		next = par;
		return toTry;
	}
}

void speedrun(int subtask, int N, int start) 
{
	if(N == 1) return;
	int l = getLength();
	next = start;
	int toTry = 0;
	for(int rep = 0; rep < 10000; rep++)
	{
		int par = 0;
		for(int i = 0; i < 10; i++) par += getHint(i + 1) * (1 << i);
		toTry = dfs(next, toTry);
	}
}

Compilation message

speedrun.cpp: In function 'void assignHints(int, int, int*, int*)':
speedrun.cpp:33:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |  for(int i = 0; i < path.size() - 1; i++)
      |                 ~~^~~~~~~~~~~~~~~~~
speedrun.cpp: In function 'int dfs(int, int)':
speedrun.cpp:58:3: error: reference to 'next' is ambiguous
   58 |   next = par;
      |   ^~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:66,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from speedrun.cpp:1:
/usr/include/c++/10/bits/stl_iterator_base_funcs.h:213:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename std::iterator_traits<_Iter>::difference_type)'
  213 |     next(_InputIterator __x, typename
      |     ^~~~
speedrun.cpp:44:5: note:                 'int next'
   44 | int next;
      |     ^~~~
speedrun.cpp: In function 'void speedrun(int, int, int)':
speedrun.cpp:67:2: error: reference to 'next' is ambiguous
   67 |  next = start;
      |  ^~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:66,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from speedrun.cpp:1:
/usr/include/c++/10/bits/stl_iterator_base_funcs.h:213:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename std::iterator_traits<_Iter>::difference_type)'
  213 |     next(_InputIterator __x, typename
      |     ^~~~
speedrun.cpp:44:5: note:                 'int next'
   44 | int next;
      |     ^~~~
speedrun.cpp:73:15: error: reference to 'next' is ambiguous
   73 |   toTry = dfs(next, toTry);
      |               ^~~~
In file included from /usr/include/c++/10/bits/stl_algobase.h:66,
                 from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from speedrun.cpp:1:
/usr/include/c++/10/bits/stl_iterator_base_funcs.h:213:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename std::iterator_traits<_Iter>::difference_type)'
  213 |     next(_InputIterator __x, typename
      |     ^~~~
speedrun.cpp:44:5: note:                 'int next'
   44 | int next;
      |     ^~~~
speedrun.cpp:66:6: warning: unused variable 'l' [-Wunused-variable]
   66 |  int l = getLength();
      |      ^