답안 #701759

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
701759 2023-02-22T05:03:49 Z Etherite Speedrun (RMI21_speedrun) C++17
컴파일 오류
0 ms 0 KB
#include "speedrun.h"
#include "bits/stdc++.h"

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());
	stack<int> toAdd;
	dfsHint(1, 0, adjHint, toAdd);
}

void dfsHint(int curr, int par, vector<set<int>> &adjHint, stack<int> &toAdd)
{
	for(int i = 9; i >= 0; i--) // set in big-endian
	{
		if(par & (1 << i)) setHint(curr, i + 1, 1);
		else setHint(curr, i + 1, 0);
	}

	for(int i = adjHint[curr].size() - 1; i >= 0; i--)
	{
		int next = adjHint[i];
		if(next == par) continue;
		toAdd.push(next);
	}
	int second = toAdd.top();
	toAdd.pop();
	for(int i = 9; i >= 0; i--)
	{
		if(second & (1 << i)) setHint(curr, i + 11, 1);
		else setHint(curr, i + 11, 0);
	}

	for(int next : adjHint[curr])
	{
		if(next == par) continue;
		dfsHint(next, curr, adjHint, toAdd);
	}
}

void speedrun(int subtask, int N, int start) 
{
	int l = getLength();
	
	int par = 0;
	for(int i = 0; i < 10; i++) par += getHint(i + 1) * (1 << i);

	vector<int> vis(N + 1);
	vis[start] = 1;
	dfsSpeedrun(start, par, vis);
}

int dfsSpeedrun(int curr, int par, vector<int> &vis)
{
	int child = 0;
	for(int i = 10; i < 20; i++) child += getHint(i + 1) * (1 << (i - 10));

	while(1)
	{
		bool canDescend = goTo(child);
		if(canDescend)
		{
			child = dfsSpeedrun(child, curr);
		}
		else return child;
	}
}

Compilation message

speedrun.cpp: In function 'void assignHints(int, int, int*, int*)':
speedrun.cpp:7:2: error: 'vector' was not declared in this scope
    7 |  vector<vector<int>> adjHint(N + 1);
      |  ^~~~~~
speedrun.cpp:7:2: note: suggested alternatives:
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from speedrun.cpp:2:
/usr/include/c++/10/bits/stl_vector.h:389:11: note:   'std::vector'
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from speedrun.cpp:2:
/usr/include/c++/10/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
speedrun.cpp:7:16: error: expected primary-expression before 'int'
    7 |  vector<vector<int>> adjHint(N + 1);
      |                ^~~
speedrun.cpp:10:3: error: 'adjHint' was not declared in this scope
   10 |   adjHint[A[i]].push_back(B[i]);
      |   ^~~~~~~
speedrun.cpp:13:35: error: 'adjHint' was not declared in this scope
   13 |  for(int i = 1; i <= N; i++) sort(adjHint[i].begin(), adjHint[i].end());
      |                                   ^~~~~~~
speedrun.cpp:13:30: error: 'sort' was not declared in this scope; did you mean 'std::sort'?
   13 |  for(int i = 1; i <= N; i++) sort(adjHint[i].begin(), adjHint[i].end());
      |                              ^~~~
      |                              std::sort
In file included from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from speedrun.cpp:2:
/usr/include/c++/10/pstl/glue_algorithm_defs.h:296:1: note: 'std::sort' declared here
  296 | sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last);
      | ^~~~
speedrun.cpp:14:2: error: 'stack' was not declared in this scope; did you mean 'std::stack'?
   14 |  stack<int> toAdd;
      |  ^~~~~
      |  std::stack
In file included from /usr/include/c++/10/stack:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:89,
                 from speedrun.cpp:2:
/usr/include/c++/10/bits/stl_stack.h:99:11: note: 'std::stack' declared here
   99 |     class stack
      |           ^~~~~
speedrun.cpp:14:8: error: expected primary-expression before 'int'
   14 |  stack<int> toAdd;
      |        ^~~
speedrun.cpp:15:16: error: 'adjHint' was not declared in this scope
   15 |  dfsHint(1, 0, adjHint, toAdd);
      |                ^~~~~~~
speedrun.cpp:15:25: error: 'toAdd' was not declared in this scope
   15 |  dfsHint(1, 0, adjHint, toAdd);
      |                         ^~~~~
speedrun.cpp:15:2: error: 'dfsHint' was not declared in this scope
   15 |  dfsHint(1, 0, adjHint, toAdd);
      |  ^~~~~~~
speedrun.cpp: At global scope:
speedrun.cpp:18:33: error: 'vector' has not been declared
   18 | void dfsHint(int curr, int par, vector<set<int>> &adjHint, stack<int> &toAdd)
      |                                 ^~~~~~
speedrun.cpp:18:39: error: expected ',' or '...' before '<' token
   18 | void dfsHint(int curr, int par, vector<set<int>> &adjHint, stack<int> &toAdd)
      |                                       ^
speedrun.cpp: In function 'void dfsHint(int, int, int)':
speedrun.cpp:26:14: error: 'adjHint' was not declared in this scope
   26 |  for(int i = adjHint[curr].size() - 1; i >= 0; i--)
      |              ^~~~~~~
speedrun.cpp:30:3: error: 'toAdd' was not declared in this scope
   30 |   toAdd.push(next);
      |   ^~~~~
speedrun.cpp:32:15: error: 'toAdd' was not declared in this scope
   32 |  int second = toAdd.top();
      |               ^~~~~
speedrun.cpp:40:17: error: 'adjHint' was not declared in this scope
   40 |  for(int next : adjHint[curr])
      |                 ^~~~~~~
speedrun.cpp: In function 'void speedrun(int, int, int)':
speedrun.cpp:54:2: error: 'vector' was not declared in this scope
   54 |  vector<int> vis(N + 1);
      |  ^~~~~~
speedrun.cpp:54:2: note: suggested alternatives:
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from speedrun.cpp:2:
/usr/include/c++/10/bits/stl_vector.h:389:11: note:   'std::vector'
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from speedrun.cpp:2:
/usr/include/c++/10/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
speedrun.cpp:54:9: error: expected primary-expression before 'int'
   54 |  vector<int> vis(N + 1);
      |         ^~~
speedrun.cpp:55:2: error: 'vis' was not declared in this scope
   55 |  vis[start] = 1;
      |  ^~~
speedrun.cpp:56:2: error: 'dfsSpeedrun' was not declared in this scope; did you mean 'speedrun'?
   56 |  dfsSpeedrun(start, par, vis);
      |  ^~~~~~~~~~~
      |  speedrun
speedrun.cpp:49:6: warning: unused variable 'l' [-Wunused-variable]
   49 |  int l = getLength();
      |      ^
speedrun.cpp: At global scope:
speedrun.cpp:59:36: error: 'vector' has not been declared
   59 | int dfsSpeedrun(int curr, int par, vector<int> &vis)
      |                                    ^~~~~~
speedrun.cpp:59:42: error: expected ',' or '...' before '<' token
   59 | int dfsSpeedrun(int curr, int par, vector<int> &vis)
      |                                          ^
speedrun.cpp: In function 'int dfsSpeedrun(int, int, int)':
speedrun.cpp:69:35: error: too few arguments to function 'int dfsSpeedrun(int, int, int)'
   69 |    child = dfsSpeedrun(child, curr);
      |                                   ^
speedrun.cpp:59:5: note: declared here
   59 | int dfsSpeedrun(int curr, int par, vector<int> &vis)
      |     ^~~~~~~~~~~