Submission #427436

# Submission time Handle Problem Language Result Execution time Memory
427436 2021-06-14T15:14:41 Z AugustinasJucas Stations (IOI20_stations) C++14
8 / 100
1577 ms 696 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int dydis = 1000;
vector<int> gr[dydis];
int enter[dydis];
int leave[dydis];
vector<int> ret (dydis);
int dbInd = 0;
void dfs(int v, int came){
	enter[v] = dbInd++;
	for(auto x : gr[v]){
		if(x == came) continue;
		dfs(x, v);
	}
	leave[v] = dbInd;
	ret[v] = enter[v] * dydis + leave[v] - 1;
	//cout << "enter " << v << " - " << enter[v] << ", o leave " << leave[v]-1 << endl;
}
void dfs1(int v, int came, int as){
	ret[v] = as;
	for(auto x : gr[v]){
		if(x == came) continue;
		dfs1(x, v, as+1);
	}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	int mxsz = 0;
	for(int i = 0; i < n; i++){
		gr[i].clear();
		gr[i].clear();
	}
	dbInd = 0;
	ret.resize(n);
	for(int i = 0; i < n-1; i++){
		gr[u[i]].push_back(v[i]);
		gr[v[i]].push_back(u[i]);
	}

	for(int i = 0; i < n; i++) mxsz = max(mxsz, (int)gr[i].size());
	//int st = 0;
	//for(int i = 0; i < n; i++) if(gr[i].size() == 1) st = i;
	//dfs1(st, -1, 1);
	for(int i = 0; i < n; i++) ret[i] = i + 1;
	return ret;
}
/*
int find_next_station(int s, int t, vector<int> c) {
	int enterS = s / 1000;
	int leaveS = s % 1000;
	int enterT = t / 1000;
	int leaveT = t % 1000;
//	cout << "kitas einant is " << s << " i " << t << " yra:\n";
	if(enterS <= enterT && leaveT <= leaveS){
	//	cout << enterS << " yra " << enterT << " tevas\n";
		for(auto x : c){
			int e = x / 1000;
			int l = x % 1000;
			if(e <= enterT && leaveT <= l && !(e <= enterS && leaveS <= l)){
		//		cout << "ret " << x << endl << endl;
				return x;
			}
		}
	}else{ // eisiu aukstyn
		for(auto x : c){
			int e = x / 1000;
			int l = x % 1000;
			if(e <= enterS && leaveS <= l){
			//	cout << "ret " << x << endl << endl;
				return x;
			}
		}
	}
	return c[0];
}
*/

int lg2(int x){
	int ret = 0;
	while(x != 0){
		ret++;
		x = x / 2;
	}
	return ret;
}

int find_next_station(int s, int t, vector<int> c) {
	int h1 = lg2(s);
	int h2 = lg2(t);
	//cout << s << " -> " << t << ", ret = ";
	if(h1 >= h2){ // s zemiau
		return s / 2;
	}
	// dabar s bus auksciau!
	int reiks = ((s << (h2 - h1)) ^ t);
	int aukBit = -1;
	for(int i  = 0; i < 30; i++) if((1 << i) & reiks) aukBit = i;
		//cout << "reiks = " << reiks << ", aukbit = " << aukBit << endl;
	if(aukBit < h2-h1){
		// s yra tevas
		int pl = ((bool)(t & (1 << (h2 - h1-1))));
		return s * 2 + pl;
	}else{
		return s / 2;
	}
	
	

}

# Verdict Execution time Memory Grader output
1 Incorrect 788 ms 664 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 734 ms 492 KB Output is correct
2 Correct 927 ms 696 KB Output is correct
3 Correct 1577 ms 488 KB Output is correct
4 Correct 917 ms 524 KB Output is correct
5 Correct 900 ms 588 KB Output is correct
6 Correct 885 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 843 ms 528 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1532 ms 420 KB Output is correct
2 Incorrect 869 ms 524 KB Wrong query response.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 730 ms 560 KB Wrong query response.
2 Halted 0 ms 0 KB -