Submission #321439

# Submission time Handle Problem Language Result Execution time Memory
321439 2020-11-12T10:42:06 Z NachoLibre Stations (IOI20_stations) C++14
0 / 100
50 ms 1208 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1003;
vector<int> v[N], dr;
int tn;

void sgd(int dg, int op, int dt) {
	if(dt & 1 ^ 1) dr[dg] = tn, ++tn;
	for(int i = 0; i < v[dg].size(); ++i) {
		if(v[dg][i] != op) {
			sgd(v[dg][i], dg, dt + 1);
		}
	}
	if(dt & 1) dr[dg] = tn, ++tn;
}

vector<int> label(int n, int k, vector<int> x, vector<int> y) {
	for(int i = 0; i < n; ++i) v[i].clear();
	for(int i = 0; i < n - 1; ++i) {
		v[x[i]].push_back(y[i]);
		v[y[i]].push_back(x[i]);
	}
	dr.clear();
	for(int i = 0; i < n; ++i) dr.push_back(0);
	tn = 0;
	sgd(0, -1, 0);
	return dr;
}

int find_next_station(int a, int b, vector<int> v) {
	int n = v.size();
	if(v[0] > a) {
		sort(v.begin(), v.end());
		if(b < a) return v[n - 1];
		for(int i = 0; i < n - 1; ++i) {
			if(b <= v[i]) return v[i];
		}
		return v[n - 1];
	} else {
		sort(v.begin(), v.end());
		v.push_back(v[0]);
		for(int i = 0; i < n; ++i) v[i] = v[i + 1];
		v.pop_back();
		///
		cout << a << " " << b << endl;
		for(int i = 0; i < v.size(); ++i) {
			cout << v[i] << " ";
		}
		cout << endl;
		///
		if(b <= v[n - 1]) return v[n - 1];
		if(b > a) return v[n - 1];
		for(int i = 1; i < n - 1; ++i) {
			if(b < v[i]) return v[i - 1];
		}
		return v[n - 2];
	}
}

// int main() {
// 	ios::sync_with_stdio(0);
// 	cin.tie(0);
// 	dr = label(5, 4, {0, 1, 1, 2}, {1, 2, 3, 4});
// 	cout << find_next_station(dr[2], dr[0], {dr[1], dr[4]}) << " --> " << dr[1] << endl;
// 	cout << find_next_station(dr[1], dr[3], {dr[3], dr[2], dr[0]}) << " --> " << dr[3] << endl;
// 	return 0;
// }

Compilation message

stations.cpp: In function 'void sgd(int, int, int)':
stations.cpp:9:8: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
    9 |  if(dt & 1 ^ 1) dr[dg] = tn, ++tn;
      |     ~~~^~~
stations.cpp:10:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for(int i = 0; i < v[dg].size(); ++i) {
      |                 ~~^~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:47:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   for(int i = 0; i < v.size(); ++i) {
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 38 ms 1208 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 25 ms 864 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 36 ms 1072 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 50 ms 864 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 36 ms 992 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -