답안 #416826

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
416826 2021-06-03T03:17:36 Z Dilshod_Imomov 기지국 (IOI20_stations) C++17
0 / 100
958 ms 55536 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
 
const int MAXN = 1e3 + 7;

vector < int > tin, tout, d;
 
void dfs( vector<vector<int>> adj, int v, int p, int h, int &cnt ) {
	tin[v] = cnt++;
	d[v] = h;
	for ( auto u: adj[v] ) {
		if ( u != p ) {
			dfs( adj, u, v, h + 1, cnt );
		}
	}
	tout[v] = cnt++;
}
 
 
vector<int> label(int n, int k, vector<int> U, vector<int> V) {
	vector < vector < int > > adj(n + 1);
	tin.resize( n + 1 );
	tout.resize( n + 1 );
	d.resize( n + 1 );
	for ( int i = 0; i < n - 1; i++ ) {
		int u = U[i], v = V[i];
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	vector < int > lb(n);
	int cnt = 0;
	dfs( adj, 0, -1, 0, cnt );
	vector < int > vc;
	for ( int i = 0; i < n; i++ ) {
		if ( i & 1 ) {
			vc.push_back( tout[i] );
		}
		else {
			vc.push_back( tin[i] );
		}
	}
	sort( vc.begin(), vc.end() );
	int x = 0;
	map < int, int > mp;
	for ( auto i: vc ) {
		mp[i] = x++;
	}
	for ( int i = 0; i < n; i++ ) {
		if ( i & 1 ) {
			lb[i] = mp[ tout[i] ];
		}
		else {
			lb[i] = mp[ tin[i] ];
		}
	}
	return lb;
}
 
int find_next_station(int s, int t, vector<int> c) {
	int sz = c.size(), pr = -1;
	int tins = -1, touts = -1;
	vector < int > tin(sz), tout(sz);
	if ( c[0] > s ) { // s is in even layer, s in tin
		tins = s;
		if ( s == 0 ) {
			touts = c.back() + 1;
		}
		else {
			touts = c[sz - 2] + 1;
			pr = c.back();
			c.pop_back();
			sz--;
		}
		tin[0] = tins + 1;
		tout[0] = c[0];
		for ( int i = 1; i < sz; i++ ) {
			tin[i] = tout[i - 1] + 1;
			tout[i] = c[i];
		}
	}
	else { // s in odd layer
		touts = s;
		if ( sz == 1 ) {
			tins = s - 1;
			return c[0];
		}
		else {
			pr = c[0];
			c.erase(c.begin());
			sz--;
			tins = c[0] - 1;
		}
		tout[sz - 1] = s - 1;
		tin[sz - 1] = c[sz - 1];
		for ( int i = sz - 2; i >= 0; i-- ) {
			tout[i] = tin[i + 1] - 1;
			tin[i] = c[i];
		}
	}
	// cout << tins << ' ' << touts << ' ' << pr << endl;
	for ( int i = 0; i < sz; i++ ) {
		int u = c[i];
		// cout << tin[i] << " " << tout[i] << endl;
		if ( tin[i] <= t && tout[i] >= t ) {
			return u;
		}
	}
	return pr;
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:62:17: warning: variable 'touts' set but not used [-Wunused-but-set-variable]
   62 |  int tins = -1, touts = -1;
      |                 ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 859 ms 55496 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 958 ms 1120 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 843 ms 55536 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 922 ms 492 KB Output is correct
2 Incorrect 607 ms 400 KB Wrong query response.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 849 ms 55516 KB Wrong query response.
2 Halted 0 ms 0 KB -