Submission #1085300

# Submission time Handle Problem Language Result Execution time Memory
1085300 2024-09-07T22:18:00 Z 4QT0R Stations (IOI20_stations) C++17
0 / 100
3000 ms 2097152 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> graph[1002];

int dep[1002];
int timer;
int pre[1002];
int post[1002];

void dfs(int v, int p){
	pre[v]=timer++;
	for (auto u : graph[v]){
		if (u==p)continue;
		dep[u]=dep[v]+1;
		dfs(u,v);
	}
	post[v]=timer++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v){
	for (int i = 0; i<n-1; i++){
		graph[u[i]].push_back(v[i]);
		graph[v[i]].push_back(u[i]);
	}
	dfs(0,-1);
	int iter=0;
	set<int> s;
	map<int,int> mp;
	for (int i = 0; i<n; i++)s.insert(dep[i]&1?post[i]:pre[i]);
	for (auto x : s)mp[x]=iter++;
	vector<int> ans(n);
	for (int i = 0; i<n; i++){
		ans[i]=mp[dep[i]&1?post[i]:pre[i]];
	}
	return ans;
}


int find_next_station(int s, int t, vector<int> c){
	int cas=1;
	for (auto u : c)if (s<u)cas=0;
	if (cas){
		int fat=c[0];
		c.erase(c.begin());
		int prv=s;
		for (int i = c.size()-1; i>=0; i--){
			if (c[i]<=t && t<prv)return c[i];
			prv=c[i];
		}
		return fat;
	}
	else{
		int fat=c.back();
		c.pop_back();
		int prv=s;
		for (int i = 0; i<c.size(); i++){
			if (prv<t && t<=c[i])return c[i];
			prv=c[i];
		}
		return fat;

	}
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:56:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for (int i = 0; i<c.size(); i++){
      |                   ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1580 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3062 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1271 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 622 ms 684 KB Output is correct
2 Runtime error 1078 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1921 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -