Submission #417690

# Submission time Handle Problem Language Result Execution time Memory
417690 2021-06-04T06:47:46 Z Bill_00 Stations (IOI20_stations) C++14
0 / 100
2118 ms 2097156 KB
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
vector<int>adj[1005];
int sz[1005],n;
vector<int> labels(1005);
vector<int>ans;
void dfs(int node,int par=-1){
	sz[node]=1;
	for(int to:adj[node]){
		if(to!=par){
			dfs(to,node);
			sz[node]+=sz[to];	
		} 
	}
	// cout << node << ' ' << sz[node] << '\n';
}
void solve(int node,int recnt,int l,int r,int par=-1){
	// cout << recnt << ' ' << l << ' ' << r << '\n';
	bool flag=0;
	labels[node]=recnt;
	if(l==recnt){
		l++;
		flag=1;
	}
	else r--;
	for(int to:adj[node]){
		if(to!=par){
			// cout << to << ' ' << l+(flag?sz[to]-1:0) << ' ' << l << ' ' << l+sz[to]-1 << '\n';
			solve(to,l+(flag?sz[to]-1:0),l,l+sz[to]-1,node);
			l=l+sz[to];
		}
	}
}
vector<int> label(int N, int k, vector<int> u, vector<int> v) {
	n=N;
	for(int i=0;i<(n-1);i++){
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}
	dfs(0);
	solve(0,0,0,n-1);
	for(int i=0;i<n;i++) ans.push_back(labels[i]);
	return ans;
}

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

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:51:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   for(int i=0;i<c.size();i++){
      |               ~^~~~~~~~~
stations.cpp:57:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   for(int i=1;i<(c.size()-1);i++){
      |               ~^~~~~~~~~~~~~
stations.cpp:65:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |   for(int i=0;i<c.size();i++){
      |               ~^~~~~~~~~
stations.cpp:68:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   for(int i=1;i<(v.size()-1);i++){
      |               ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1541 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 400 KB Invalid length of array as the response of 'label'. scenario=1, n=994, len=1990
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1312 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 200 KB Invalid length of array as the response of 'label'. scenario=1, n=2, len=4
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2118 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -