답안 #417717

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
417717 2021-06-04T07:58:50 Z Bill_00 기지국 (IOI20_stations) C++14
0 / 100
2132 ms 2097156 KB
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
vector<int>adj[1005];
vector<int> labels(1005);
int sz[1005],n;
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];	
		} 
	}
}
void solve(bool flag,int node,int l,int r,int par=-1){
	labels[node]=(flag?l:r);
	if(flag) l++;
	for(int to:adj[node]){
		if(to!=par){
			solve(flag^1,to,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(1,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<((int)c.size())-1;i++){
			if(c[i]<=t && t<c[i+1]) return c[i];
		}
		return c[0];
	}
	else{
		vector<int>q;
		q.push_back(s);
		for(int i=0;i<c.size();i++){
			q.push_back(c[i]);
		}
		for(int i=1;i<((int)q.size())-1;i++){
			if(q[i-1]<t && t<=q[i]) return q[i];
		}
		return q.back();
	}
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:43:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   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=0;i<c.size();i++){
      |               ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1364 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 300 KB Invalid length of array as the response of 'label'. scenario=1, n=994, len=1990
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1336 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2132 ms 2097156 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -