답안 #313986

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
313986 2020-10-17T17:29:20 Z dlwocks31 기지국 (IOI20_stations) C++17
0 / 100
3000 ms 2097156 KB
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[1000];
int lbl[1000], cnt;
void dfs(int i, int p, int d) {
	if(d % 2 == 0)
		lbl[i] = cnt++;
	for(int a: adj[i]) {
		if(a == p) continue;
		dfs(a, i, d+1);
	}
	if(d % 2 == 1)
		lbl[i] = cnt++;
}
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++) {
		//printf("edge = %d, %d\n", u[i], v[i]);
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}
	dfs(0, -1, 0);
	for(int i=0; i<n; i++) {
		//printf("label %d = %d\n", i, lbl[i]);
		labels[i] = lbl[i];
	}
	return labels;
}

int find_next_station(int s, int t, vector<int> c) {
	if(c[0] < s) { // s is out
		reverse(c.begin(), c.end());
	}
	c.insert(c.begin(), s);
	for(int i=1; i<c.size(); i++) {
		//printf("compare between %d, %d\n", c[i-1], c[i]);
		if((c[i-1] <= t && t <= c[i]) || (c[i] <= t && t <= c[i-1])) {
			return c[i];
		}
	}
	return c.back();
}

// int main() {
// 	int s, t, w;
// 	cin >> s >> t >> w;
// 	vector<int> c(w);
// 	for(int i=0; i<w; i++) {
// 		cin >> c[i];
// 	}
// 	cout << find_next_station(s, t, c);
// }

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:18:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  for(int i=0; i<u.size(); i++) {
      |               ~^~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:36:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for(int i=1; i<c.size(); i++) {
      |               ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1424 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3063 ms 504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1489 ms 2097152 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 954 ms 876 KB Output is correct
2 Runtime error 1272 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2412 ms 2097156 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -