Submission #349943

# Submission time Handle Problem Language Result Execution time Memory
349943 2021-01-18T18:27:53 Z evn Stations (IOI20_stations) C++14
0 / 100
3000 ms 2097156 KB
#include <bits/stdc++.h>
#include "stations.h"
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
typedef long long ll;
typedef pair<int, int> pii;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int timer = 0;
int depth[1005];
int in[1005];
int out[1005];
vector<int> adj[1005];
void dfs(int u, int p){
	in[u] = timer++;
	for(int v : adj[u]){
		if(v != p){
			depth[v] = depth[u]+1;
			dfs(v, u);
		}
	}
	out[u] = timer++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	vector<int> labels(n);
	for(int i = 0; i < u.size(); i++){
		int a, b;
		a = u[i];
		b = v[i];
		adj[a].pb(b);
		adj[b].pb(a);
	}
	dfs(0, -1);
	for (int i = 0; i < n; i++) {
		if(depth[i] % 2 == 0)labels[i] = in[i];
		else{labels[i] = out[i];}
	}
	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	int lessThan = 0;
	for(int u : c){
		if(u < s)lessThan++;
	}
	if(lessThan == c.size()){
		//out
		if(c.size() == 1){
			return c[0];
		}
		int in = c[1];
		in--;
		if(t >= in && t <= s){
			//node is in this subtree
			for(int i =1; i < c.size(); i++){
				int out = (i == c.size()-1 ? s-1:c[i+1]-1);
				if(t >= c[i] && t <= out){
					return c[i];
				}
			}
		}
		else{
			//go to parent
			return c[0];
		}
	}
	else{
		//this is the in value
		if(c.size() == 1){
			return c[0];
		}
		int out = c[c.size() - 1]+1;
		if(t >= s && t <= out){
			//node is in this subtree
			if(s == 0){
				for(int i = 0; i < c.size(); i++){
					int in = (i == 0 ? s+1:c[i-1]+1);
					if(t >= in && t <= c[i]){
						return c[i];
					}
				}
			}
			else{
				for(int i = 1; i < c.size(); i++){
					int in = (i == 1 ? s+1 : c[i-1] + 1);
					if(t >= in && t <= c[i])return c[i];
				}	
			}
		}
		else{
			//go to parent
			return c[0];
		}
	}
	return c[0];
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  for(int i = 0; i < u.size(); i++){
      |                 ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:52:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  if(lessThan == c.size()){
      |     ~~~~~~~~~^~~~~~~~~~~
stations.cpp:61:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |    for(int i =1; i < c.size(); i++){
      |                  ~~^~~~~~~~~~
stations.cpp:62:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     int out = (i == c.size()-1 ? s-1:c[i+1]-1);
      |                ~~^~~~~~~~~~~~~
stations.cpp:82:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for(int i = 0; i < c.size(); i++){
      |                    ~~^~~~~~~~~~
stations.cpp:90:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |     for(int i = 1; i < c.size(); i++){
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1435 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3051 ms 512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1512 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 839 ms 748 KB Output is correct
2 Runtime error 1244 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2511 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -