제출 #1045259

#제출 시각아이디문제언어결과실행 시간메모리
1045259n1kStations (IOI20_stations)C++17
0 / 100
499 ms1196 KiB
#include "stations.h"
#include <vector>
#include <bits/stdc++.h>

using namespace std;

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	vector<vector<int>> g(n);
	for(int i=0; i+1<n; i++){
		g[u[i]].push_back(v[i]);
		g[v[i]].push_back(u[i]);
	}
	vector<int> l(n);
	int t = 0;
	function<void(int, int, int)> dfs = [&](int u, int d, int p){
		if(d%2==0){
			l[u]=t++;
		}
		for(int v:g[u]){
			if(v==p){
				continue;
			}
			dfs(v, d+1, u);	
		}
		if(d%2==1){
			l[u]=t++;
		}
	};
	dfs(0, 0, -1);
	return l;
}

int find_next_station(int s, int t, std::vector<int> c) {
	if(c.size()==1){
		return c[0];
	}
	if(c.back()<s){
		// saved time is tout
		// check if we hold it
		int tin = c[0], tout = s;
		if(not (tin <= t and t < tout)){
			return c[0];
		}
		for(int i=1; i<c.size(); i++){
			tin = c[i], tout = (i+1 < c.size() ? c[i+1] : s);
			if(tin <= t and t < tout){
				return c[i];
			}
		}
		// we hold it if tin <= t < tout or s == 0
		// if not go to par
	}else{
		int tin = s, tout = c[c.size()-2];
		if(not (tin < t and t <= tout)){
			return c.back();
		}
		if(s!=0){
			c.pop_back();
		}
		for(int i=0; i<c.size(); i++){
			tin = (i-1>=0 ? c[i-1] : s), tout = c[i];
			if(tin < t and t<= tout){
				return c[i];
			}
		}
	}
	assert(false);
}

컴파일 시 표준 에러 (stderr) 메시지

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:44:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |   for(int i=1; i<c.size(); i++){
      |                ~^~~~~~~~~
stations.cpp:45:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |    tin = c[i], tout = (i+1 < c.size() ? c[i+1] : s);
      |                        ~~~~^~~~~~~~~~
stations.cpp:60:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   for(int i=0; i<c.size(); i++){
      |                ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...