Submission #399060

# Submission time Handle Problem Language Result Execution time Memory
399060 2021-05-05T08:29:29 Z Antekb Stations (IOI20_stations) C++14
0 / 100
3000 ms 2097156 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
const int N=1005;
int pre[N], post[N], d[N];
vector<int> E[N];
int wsk;
void dfs(int v, int p){
	//cout<<v<<" "<<p<<" "<<wsk<<"\n";
	pre[v]=wsk++;
	for(int u:E[v]){
		if(u!=p){
			d[u]=d[v]+1;
			dfs(u, v);
		}
	}
	post[v]=wsk++;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	for(int i=0; i<n-1; i++){
		E[u[i]].push_back(v[i]);
		E[v[i]].push_back(u[i]);
	}
	std::vector<int> labels(n);
	dfs(0, -1);
	for (int i = 0; i < n; i++) {
		if(d[i]&1)labels[i] = pre[i];
		else labels[i]=post[i];
		//cout<<i<<" "<<labels[i]<<"\n";
	}
	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	sort(c.begin(), c.end());
	bool ma=1;
	for(int i:c){
		if(i>s)ma=0;
	}
	if(ma){
		if(t>=s)return c[0];
		for(int i=c.size()-1; i>0; i--){
			if(c[i]<=t)return c[i];
		}
		return c[0];
	}
	else{
		//reverse(c.begin(), c.end());
		if(t<s)return c.back();
		for(int i=0; i<c.size(); i++){
			if(c[i]>=t)return c[i];
		}
		return c.back();
	}
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:50:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |   for(int i=0; i<c.size(); i++){
      |                ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1562 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3048 ms 420 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1398 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1029 ms 536 KB Output is correct
2 Runtime error 1143 ms 2097156 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2380 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -