Submission #1080826

# Submission time Handle Problem Language Result Execution time Memory
1080826 2024-08-29T14:39:11 Z mathematik Stations (IOI20_stations) C++17
0 / 100
574 ms 940 KB
#include "stations.h"
#include <bits/stdc++.h>

using namespace std;

void calc_size(vector<vector<int>> & adj, vector<int> & sz, vector<bool> & v, int i) {
	v[i] = true;
	for (int n: adj[i]) {
		if (v[n]) continue; 
		calc_size(adj, sz, v, n);
		sz[i] += sz[n];
	}
}

void calc_label(vector<vector<int>> & adj, vector<int> & sz, vector<bool> & v, int i, int l, int r, vector<int> & label, bool high) {
	v[i] = true;
	label[i] = high ? --r : l++;
	for (int n: adj[i]) {
		if (v[n]) continue; 
		calc_label(adj, sz, v, n, l, l + sz[n], label, !high);
		l += sz[n];
	}
}

vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	vector<vector<int>> adj(n);
	for (int i = 0; i < n - 1; i++)
	{
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}
	vector<int> sz(n, 1);
	vector<bool> v_(n, false);
	calc_size(adj, sz, v_, 0);
	vector<int> label(n);
	v_ = vector<bool>(n, false);
	calc_label(adj, sz, v_, 0, 0, n, label, false);
	return label;
}

int find_next_station(int s, int t, vector<int> c) {
	if (c.size() == 1) return c[0];
	sort(c.begin(), c.end());
	if (s == 0) {
		for (int i = 0; i < c.size() - 1; i++)
		{
			if (c[i] <= s && s < c[i + 1]) return c[i];
		}
		return c.back();
	}
	if (c[0] < s) {
		if (s < t || c[1] > t) return c.front();
		for (int i = 1; i < c.size() - 1; i++)
		{
			if (s >= c[i] && s < c[i + 1]) return c[i];
		}
		return c.back();
 	} else {
		if (s > t || c[1] < t) return c.back();
		for (int i = c.size() - 2; i >= 1; i--)
		{
			if (s <= c[i] && s > c[i + 1]) return c[i];
		}
		return c.front();
	}
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:45:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for (int i = 0; i < c.size() - 1; i++)
      |                   ~~^~~~~~~~~~~~~~
stations.cpp:53:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for (int i = 1; i < c.size() - 1; i++)
      |                   ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 325 ms 940 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 322 ms 684 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 373 ms 940 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 574 ms 768 KB Output is correct
2 Incorrect 457 ms 688 KB Wrong query response.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 360 ms 940 KB Wrong query response.
2 Halted 0 ms 0 KB -