Submission #828532

# Submission time Handle Problem Language Result Execution time Memory
828532 2023-08-17T10:50:01 Z GrindMachine Speedrun (RMI21_speedrun) C++17
100 / 100
189 ms 920 KB
// Om Namah Shivaya

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x, y) ((x + y - 1) / (y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep1(i, n) for(int i = 1; i <= n; ++i)
#define rev(i, s, e) for(int i = s; i >= e; --i)
#define trav(i, a) for(auto &i : a)

template<typename T>
void amin(T &a, T b) {
    a = min(a, b);
}

template<typename T>
void amax(T &a, T b) {
    a = max(a, b);
}

#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif

/*



*/

const int MOD = 1e9 + 7;
const int N = 1e3 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;

#include "speedrun.h"

vector<int> adj[N];
vector<int> par(N);
vector<int> order;

void dfs(int u, int p){
	par[u] = p;
	order.pb(u);
	trav(v,adj[u]){
		if(v == p) conts;
		dfs(v,u);
	}
}

void assignHints(int subtask, int n, int A[], int B[]) { /* your solution here */
	rep1(i,n-1){
		int u = A[i], v = B[i];
		adj[u].pb(v), adj[v].pb(u);
	}

	dfs(1,-1);

	setHintLen(20);

	rep(i,n){
		// first 10 bits = par
		// next 10 bits = next guy in tin time order 

		int u = order[i];
		if(u != 1){
			int p = par[u];
			rep(bit,10){
				int b = 0;
				if(p & (1<<bit)) b = 1;
				setHint(u,bit+1,b);
			}
		}

		if(i+1 < n){
			int nxt = order[i+1];
			rep(bit,10){
				int b = 0;
				if(nxt & (1<<bit)) b = 1;
				setHint(u,bit+11,b);
			}
		}
	}
}

void speedrun(int subtask, int n, int start) { /* your solution here */
	rep1(i,n){
		assert(adj[i].empty());
	}
	
	while(start != 1){
		int p = 0;
		rep(bit,10){
			if(getHint(bit+1)){
				p |= (1<<bit);
			}
		}

		goTo(p);
		start = p;
	}

	int vis_cnt = 1;
	int u = 1;

	while(vis_cnt < n){
		int v = 0;
		rep(bit,10){
			if(getHint(bit+11)){
				v |= (1<<bit);
			}
		}

		while(true){
			bool ok = goTo(v);
			if(ok) break;
			goTo(par[u]);
			u = par[u];
		}

		par[v] = u;
		u = v;
		vis_cnt++;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 178 ms 708 KB Output is correct
2 Correct 167 ms 724 KB Output is correct
3 Correct 138 ms 708 KB Output is correct
4 Correct 87 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 163 ms 716 KB Output is correct
2 Correct 155 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 177 ms 672 KB Output is correct
2 Correct 189 ms 716 KB Output is correct
3 Correct 143 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 179 ms 672 KB Output is correct
2 Correct 86 ms 820 KB Output is correct
3 Correct 177 ms 736 KB Output is correct
4 Correct 159 ms 740 KB Output is correct
5 Correct 189 ms 712 KB Output is correct
6 Correct 145 ms 804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 142 ms 716 KB Output is correct
2 Correct 111 ms 848 KB Output is correct
3 Correct 114 ms 724 KB Output is correct
4 Correct 155 ms 740 KB Output is correct
5 Correct 135 ms 712 KB Output is correct
6 Correct 122 ms 708 KB Output is correct
7 Correct 112 ms 920 KB Output is correct