답안 #832639

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832639 2023-08-21T12:52:35 Z JoenPoenMan 기지국 (IOI20_stations) C++17
0 / 100
700 ms 680 KB
#include "stations.h"
#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

#define ALL(v) v.begin(), v.end()

vvi el;
bitset<1001> visited{};
vi counts{};
vi labelsOut{};

int countStations(int n) {
	visited[n] = true;
	int count = 1;
	for (int to : el[n]) {
		if (!visited[to]) {
			count += countStations(to);
		}
	}
	counts[n] = count;
	return count;
}

void assign(int n, int u, int l, bool upperbound) {
	int c = 0;
	for (int to : el[n]) {
		if (labelsOut[to] == -1) {
			labelsOut[to] = u - c - (upperbound ? 0 : counts[to] - 1);
			assign(to, u - c - (upperbound ? 1 : 0), u - c - counts[to] + 1 + (upperbound ? 0 : 1), !upperbound);
			c += counts[to];
		}
	}
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	el.resize(n);
	counts.resize(n);
	labelsOut.assign(n, -1);
	for (int i = 0; i < n-1; i++) {
		el[u[i]].push_back(v[i]);
		el[v[i]].push_back(u[i]);
	}
	countStations(0);
	labelsOut[0] = 0;
	assign(0, n-1, 1, true);
	return labelsOut;
}

int find_next_station(int s, int t, std::vector<int> c) {
	bool upperbound = s < c[0];
	int cz = c.size();
	int prev = (upperbound ? c.back() : c[0]);
	if (upperbound) {
		if (t < s || t > c[cz-2]) return prev;
		auto res = lower_bound(ALL(c), t);
		return *res;
	} else {
		if (t > s || t < c[1]) return prev;
		auto res = upper_bound(ALL(c), t);
		res--;
		return *res;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 680 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 380 KB Invalid labels (values out of range). scenario=1, k=1000, vertex=6, label=-2
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 680 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 700 ms 500 KB Output is correct
2 Incorrect 613 ms 512 KB Wrong query response.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 464 KB Invalid labels (duplicates values). scenario=1, label=877
2 Halted 0 ms 0 KB -