답안 #397930

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
397930 2021-05-03T11:51:01 Z cfalas 기지국 (IOI20_stations) C++14
0 / 100
1156 ms 652 KB
#include "stations.h"
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;

#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)

vector<vi> adj;
vi labels;
int cnt=0;
vi sub;
int d=0;
void dfs(int s, int p=-1){
	d++;
	//cout<<"enter "<<s<<" "<<cnt<<endl;
	labels[s] = cnt++;
	for(auto v : adj[s]) if(v!=p) dfs(v, s), sub[s]+=sub[v];
	d--;
	//cout<<"leave "<<s<<" "<<cnt<<endl;
	if(d%2==1) labels[s] = cnt;
	cnt++;

}

vi label(int n, int k, std::vector<int> u, std::vector<int> v) {
	cnt = 0;
	adj.assign(n, vi());
	sub.assign(n, 1);
	labels.assign(n, 0);
	FOR(i,n-1){
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}
	dfs(0);
	//FOR(i,n) cout<<labels[i]<<" "<<sub[i]-1<<endl;
	//FOR(i,n) labels[i] = labels[i]*1000 + sub[i] - 1;

	//FOA(v, labels) cout<<v<<" "; cout<<endl;

	return labels;
}

int get_s(int x){ return x % 1000; }

int find_next_station(int s, int t, std::vector<int> c) {
	sort(c.begin(), c.end());
	if(s<c[0]){
		// s is t_in
		// c is t_out
		//cout<<s<<" "<<t<<endl;
		int prev = s;
		FOA(v,c){
			if(prev<t && t<=v) return v;
			prev = v;
		}
		return c.back();
	}
	else{
		// s is t_out
		// c is t_in
		reverse(c.begin(), c.end());
		int prev = c[0];
		FOA(v,c){
			if(v<t && t<=prev) return v;
			prev = v;
		}
		return c.back();
	}
	//cout<<s<<" "<<t<<endl;
	int lt = t/1000;
	int ls = s/1000;

	int prev = ls;
	sort(c.begin(), c.end());
	FOA(x, c){
		if((x/1000)<ls) continue;
		int xs = get_s(x);
		if(prev<lt && lt<=prev+xs+1) return x;
		prev+=xs+1;
	}
	//cout<<s<<" "<<get_s(s)<<endl;
	return *min_element(c.begin(), c.end());

}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 452 KB Invalid labels (values out of range). scenario=2, k=1000, vertex=1, label=1990
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 396 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1022
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 635 ms 652 KB Wrong query response.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1156 ms 400 KB Output is correct
2 Incorrect 795 ms 400 KB Wrong query response.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 664 ms 620 KB Wrong query response.
2 Halted 0 ms 0 KB -