Submission #505009

# Submission time Handle Problem Language Result Execution time Memory
505009 2022-01-10T11:41:05 Z TranGiaHuy1508 Speedrun (RMI21_speedrun) C++17
100 / 100
230 ms 916 KB
#include <bits/stdc++.h>
using namespace std;

#include "speedrun.h"

using vi = vector<int>;
using vvi = vector<vi>;

#define pb push_back

void fset(int x, int pos, int val){
	int y = 1;
	if (pos) y += 10;

	for (int c = 0; c < 10; c++){
		setHint(x, y+c, (bool)((val >> (9 - c)) & 1));
	}
}

int fget(int pos){
	int y = 1;
	if (pos) y += 10;

	int res = 0;
	for (int c = 0; c < 10; c++){
		res = res * 2 + (int)(getHint(y+c));
	}

	return res;
}

vvi adj;
vi dfsorder, parent;

void dfs(int x, int p = -1){
	dfsorder.pb(x);
	parent[x] = (p < 0 ? 1022 : p);

	for (auto k: adj[x]){
		if (k - p){
			dfs(k, x);
		}
	}
}

void assignHints(int subtask, int N, int a[], int b[]){

	// cout << "*\n";

	setHintLen(20);

	adj.assign(N+1, vi());

	for (int i=1; i<N; i++){
		adj[a[i] - 1].pb(b[i] - 1);
		adj[b[i] - 1].pb(a[i] - 1);
	}

	parent.assign(N+1, 1022);
	dfs(0);

	// cout << "DEBUG: [";
	// for (int i=0; i<N; i++) cout << parent[i] << ", ";
	// cout << "]\n";


	for (int i=0; i<N; i++){
		fset(i+1, 0, parent[i] + 1);
	}
	for (int i=0; i<(int)dfsorder.size()-1; i++){
		fset(dfsorder[i] + 1, 1, dfsorder[i+1] + 1);
	}
}

void speedrun(int subtask, int N, int start){
	// getLength() = 20

	// cout << "*\n";

	int c = start;
	int p = fget(0);
	while (p < 1020){
		// cout << "p = " << p << "\n";
		goTo(p);
		// cout << "Here\n";
		c = p;
		// cout << "Here2\n";
		p = fget(0);
		// cout << "Here3\n";
	}

	// at root
	vi r(N+1, 0); int sm = 1;
	r[c] = 1;

	// int debug = 0;
	// while ((sm < N) && (debug < 10)){
	while (sm < N){

		// cout << "DEBUG: [";
		// for (int i=1; i<=N; i++) cout << r[i] << ", ";
		// cout << "]\n";

		int val = fget(1);
		bool test = goTo(val);
		// cout << val << " " << test << "\n";
		while (!test){
			goTo(fget(0));
			test = goTo(val);
		}
		c = val;
		sm -= r[c];
		r[c] = 1;
		sm++;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 205 ms 676 KB Output is correct
2 Correct 218 ms 672 KB Output is correct
3 Correct 197 ms 804 KB Output is correct
4 Correct 210 ms 800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 195 ms 916 KB Output is correct
2 Correct 161 ms 668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 676 KB Output is correct
2 Correct 197 ms 696 KB Output is correct
3 Correct 204 ms 656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 149 ms 680 KB Output is correct
2 Correct 191 ms 796 KB Output is correct
3 Correct 180 ms 656 KB Output is correct
4 Correct 230 ms 660 KB Output is correct
5 Correct 224 ms 676 KB Output is correct
6 Correct 216 ms 668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 222 ms 704 KB Output is correct
2 Correct 169 ms 716 KB Output is correct
3 Correct 144 ms 828 KB Output is correct
4 Correct 204 ms 704 KB Output is correct
5 Correct 211 ms 704 KB Output is correct
6 Correct 149 ms 712 KB Output is correct
7 Correct 211 ms 668 KB Output is correct