Submission #432847

# Submission time Handle Problem Language Result Execution time Memory
432847 2021-06-18T14:13:50 Z lior5654 Stations (IOI20_stations) C++17
10 / 100
841 ms 664 KB
#include <bits/stdc++.h>

using namespace std;


typedef long long int ll;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
typedef vector<vpl> vvpl;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(c) (c.begin()), (c.end())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second


#include "stations.h"


const int maxn = 1e3 + 5;


vi g[maxn];
int st[maxn]; int en[maxn]; int dt = -1;

void dfs(int c, int p=-1) {
	st[c] = ++dt; 
	for(auto e  : g[c]) {
		if(e!=p) {
			dfs(e, c);
		}
	}
	en[c] = dt;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {

	rep(i, n-1) {
		g[u[i]].pb(v[i]); g[v[i]].pb(u[i]);
	}
	dfs(0);
	vi res(n);
	rep(i, n) {
		res[i] = 1000*en[i] + st[i];
	}
	/*cout << "debug" << endl;
	rep(i, n) {
		cout << st[i] << ' '<< en[i] << endl;
	}
	for(auto e : res) {
		cout << e << ' ';
	}
	cout << endl;
	*/
	rep(i, n) {
		g[i].clear(); st[i] = 0; en[i] = 0;
	}
	dt = 0;
	return res;
}

int find_next_station(int s, int t, std::vector<int> c) {
	int s_st = s % 1000;
	int t_st = t % 1000;
	int s_en = s / 1000;
	int t_en = t / 1000;
	vi childs;
	int best = 0;
	for(int i = 1; i < c.size(); ++i) {
		if(c[i] % 1000 < c[best] % 1000) {
			best = i;
		}
	}
	int papa_label = c[best];
	int papa_st = papa_label % 1000;
	int papa_en = papa_label / 1000;
	if(papa_st < s_st) { // there's a papa
		for(auto e : c) {
			if(e != papa_label) {
				childs.pb(e);
			}
		}
	} else { // there's no papa
		for(auto e : c) {
			childs.pb(e);
		}
	}
	if(papa_st < s_st) {
		if(t_st > s_en || t_st < s_st) {
			return papa_label;
		}
	}
	sort(all(childs), [&](int xx, int yy) {
		return xx % 1000 < yy % 1000;
	});
	// find the first child whose end time is bigger than or equal to t's start time
	for(int i = 0; i < childs.size(); ++i) {
		if(childs[i] / 1000 >= t_st) return childs[i];
	}
	
	assert(false);
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:77:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |  for(int i = 1; i < c.size(); ++i) {
      |                 ~~^~~~~~~~~~
stations.cpp:105:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |  for(int i = 0; i < childs.size(); ++i) {
      |                 ~~^~~~~~~~~~~~~~~
stations.cpp:74:6: warning: unused variable 't_en' [-Wunused-variable]
   74 |  int t_en = t / 1000;
      |      ^~~~
stations.cpp:84:6: warning: unused variable 'papa_en' [-Wunused-variable]
   84 |  int papa_en = papa_label / 1000;
      |      ^~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 416 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=9000
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 320 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=0, label=995000
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 312 KB Invalid labels (values out of range). scenario=4, k=1000000, vertex=0, label=1000001
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 815 ms 400 KB Output is correct
2 Correct 582 ms 468 KB Output is correct
3 Correct 602 ms 400 KB Output is correct
4 Correct 5 ms 468 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 615 ms 520 KB Output is correct
8 Correct 841 ms 512 KB Output is correct
9 Correct 646 ms 556 KB Output is correct
10 Correct 586 ms 472 KB Output is correct
11 Correct 7 ms 468 KB Output is correct
12 Correct 5 ms 468 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 4 ms 480 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 545 ms 664 KB Output is correct
17 Correct 537 ms 400 KB Output is correct
18 Correct 522 ms 520 KB Output is correct
19 Correct 497 ms 528 KB Output is correct
20 Correct 505 ms 400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 546 ms 528 KB Wrong query response.
2 Halted 0 ms 0 KB -