Submission #701794

# Submission time Handle Problem Language Result Execution time Memory
701794 2023-02-22T06:40:24 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(par & (1 << (i - 10))) setHint(curr, i + 1, 1);
			else setHint(curr, i + 1, 0);
		}
	}
}

pair<int, int> dfs(int curr, int toTry, set<int> &vis) // returns (next curr, value to try)
{
	vis.insert(curr);

	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 make_pair(par, 0);
	
	if(goTo(toTry))
	{
		pair<int, int> res = dfs(toTry, 0, vis);
		return make_pair(par, res.second);
	}
	else return make_pair(par, toTry);
}

void speedrun(int subtask, int N, int start) 
{
	if(N == 1) return;
	int l = getLength();

	set<int> vis;
	pair<int, int> next = make_pair(start, 0);
	while(vis.size() < N)
	{
		next = dfs(next.first, next.second, vis);
	}
}

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:38:7: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   38 |    if(par & (1 << (i - 10))) setHint(curr, i + 1, 1);
      |       ^~~
      |       __pstl::execution::v1::par
In file included from /usr/include/c++/10/pstl/glue_algorithm_defs.h:15,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from speedrun.cpp:1:
/usr/include/c++/10/pstl/execution_defs.h:111:27: note: '__pstl::execution::v1::par' declared here
  111 | constexpr parallel_policy par{};
      |                           ^~~
speedrun.cpp:38:38: error: 'curr' was not declared in this scope
   38 |    if(par & (1 << (i - 10))) setHint(curr, i + 1, 1);
      |                                      ^~~~
speedrun.cpp:39:17: error: 'curr' was not declared in this scope
   39 |    else setHint(curr, i + 1, 0);
      |                 ^~~~
speedrun.cpp:35:7: warning: unused variable 'child' [-Wunused-variable]
   35 |   int child = path[i + 1];
      |       ^~~~~
speedrun.cpp: In function 'void speedrun(int, int, int)':
speedrun.cpp:70:19: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   70 |  while(vis.size() < N)
      |        ~~~~~~~~~~~^~~
speedrun.cpp:66:6: warning: unused variable 'l' [-Wunused-variable]
   66 |  int l = getLength();
      |      ^