Submission #560467

# Submission time Handle Problem Language Result Execution time Memory
560467 2022-05-11T13:36:50 Z AlperenT Stations (IOI20_stations) C++17
65.3205 / 100
834 ms 764 KB
#include "stations.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 1e3 + 5;

int t, tin[N], tout[N];
vector<int> tree[N], labels;

void dfs1(int v, int p, int x){
	labels[v] = x;

	for(auto e : tree[v]){
		if(e != p) dfs1(e, v, x + 1);
	}
}

void dfsgood(int v, int p){
	tin[v] = ++t;

	for(auto e : tree[v]){
		if(e != p) dfsgood(e, v);
	}

	tout[v] = t;
}

vector<int> label(int n, int k, vector<int> u, vector<int> v){
	labels.assign(n, -1);

	for(int i = 0; i < n; i++) tree[i].clear(), tin[i] = tout[i] = 0;

	for(int i = 0; i < n - 1; i++){
		tree[u[i]].push_back(v[i]);
		tree[v[i]].push_back(u[i]);
	}

	if(k == 1000){    // subtask 1, 2
		int mx = 0;

		for(int i = 0; i < n; i++) mx = max(mx, (int)tree[i].size());

		if(mx <= 2){    // subtask 1
			for(int i = 0; i < n; i++){
				if(tree[i].size() == 1){
					dfs1(i, -1, 0);
					break;
				}
			}
		}
		else{    // subtask 2
			for(int i = 0; i < n; i++) labels[i] = i;
		}
	}
	else{    // subtask 3, 4, 5
		t = -1;
		dfsgood(0, -1);

		for(int i = 0; i < n; i++) labels[i] = tout[i] * 1000 + tin[i];
	}

	return labels;
}

bool ispar(int ain, int aout, int bin, int bout){
	if(bin >= ain && bout <= aout) return true;
	else return false;
}

int find_next_station(int s, int t, vector<int> c){
	if(c.size() == 1) return c[0];
	else{
		if(c.size() == 2 && s < 1000 && c[0] == s - 1 && c[1] == s + 1){    // subtask 1
			if(t < s) return c[0];
			else return c[1];
		}
		else if(s < 1000){    // subtask 2
			int p, l, r;

			if(s == 0) l = c[0], r = c[1];
			else p = c[0], l = c[1], r = c.size() == 3 ? c[2] : -1;

			if(t < s) return p;
			else{
				if(t == l) return l;
				else if(r != -1 && t == r) return r;

				while(t > 0){
					if((t - 1) / 2 == l) return l;
					else if(r != -1 && (t - 1) / 2 == r) return r;

					t = (t - 1) / 2;
				}

				return p;
			}
		}
		else{    // subtask 3, 4, 5
			int ssin, ssout, ttin, ttout;

			ssin = s % 1000, ssout = s / 1000, ttin = t % 1000, ttout = t / 1000;

			vector<int> tin(c.size(), 0), tout(c.size(), 0);

			for(int i = 0; i < c.size(); i++) tin[i] = c[i] % 1000, tout[i] = c[i] / 1000;

			for(int i = 0; i < c.size(); i++){
				if(!ispar(tin[i], tout[i], ssin, ssout) && ispar(tin[i], tout[i], ttin, ttout)) return c[i];
			}

			for(int i = 0; i < c.size(); i++){
				if(ispar(tin[i], tout[i], ssin, ssout)) return c[i];
			}

			return -1;
		}
	}
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:106:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |    for(int i = 0; i < c.size(); i++) tin[i] = c[i] % 1000, tout[i] = c[i] / 1000;
      |                   ~~^~~~~~~~~~
stations.cpp:108:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |    for(int i = 0; i < c.size(); i++){
      |                   ~~^~~~~~~~~~
stations.cpp:112:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |    for(int i = 0; i < c.size(); i++){
      |                   ~~^~~~~~~~~~
stations.cpp:84:21: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   84 |    if(t < s) return p;
      |                     ^
# Verdict Execution time Memory Grader output
1 Correct 510 ms 528 KB Output is correct
2 Correct 383 ms 528 KB Output is correct
3 Correct 778 ms 420 KB Output is correct
4 Correct 638 ms 420 KB Output is correct
5 Correct 552 ms 528 KB Output is correct
6 Correct 431 ms 532 KB Output is correct
7 Correct 376 ms 544 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 5 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 483 ms 544 KB Output is correct
2 Correct 550 ms 548 KB Output is correct
3 Correct 820 ms 532 KB Output is correct
4 Correct 645 ms 596 KB Output is correct
5 Correct 450 ms 544 KB Output is correct
6 Correct 401 ms 548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 504 ms 524 KB Output is correct
2 Correct 419 ms 524 KB Output is correct
3 Correct 731 ms 524 KB Output is correct
4 Correct 627 ms 416 KB Output is correct
5 Correct 556 ms 524 KB Output is correct
6 Correct 377 ms 520 KB Output is correct
7 Correct 381 ms 548 KB Output is correct
8 Correct 2 ms 500 KB Output is correct
9 Correct 4 ms 500 KB Output is correct
10 Correct 0 ms 492 KB Output is correct
11 Correct 511 ms 532 KB Output is correct
12 Correct 457 ms 648 KB Output is correct
13 Correct 433 ms 744 KB Output is correct
14 Correct 388 ms 548 KB Output is correct
15 Correct 43 ms 596 KB Output is correct
16 Correct 59 ms 588 KB Output is correct
17 Correct 100 ms 696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 713 ms 416 KB Output is correct
2 Correct 568 ms 548 KB Output is correct
3 Correct 570 ms 528 KB Output is correct
4 Correct 2 ms 500 KB Output is correct
5 Correct 4 ms 488 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 461 ms 524 KB Output is correct
8 Correct 733 ms 524 KB Output is correct
9 Correct 550 ms 544 KB Output is correct
10 Correct 489 ms 416 KB Output is correct
11 Correct 4 ms 620 KB Output is correct
12 Correct 4 ms 628 KB Output is correct
13 Correct 5 ms 492 KB Output is correct
14 Correct 3 ms 492 KB Output is correct
15 Correct 2 ms 500 KB Output is correct
16 Correct 438 ms 416 KB Output is correct
17 Correct 439 ms 528 KB Output is correct
18 Correct 458 ms 524 KB Output is correct
19 Correct 433 ms 524 KB Output is correct
20 Correct 444 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 455 ms 532 KB Partially correct
2 Partially correct 369 ms 532 KB Partially correct
3 Partially correct 690 ms 516 KB Partially correct
4 Partially correct 555 ms 540 KB Partially correct
5 Partially correct 476 ms 420 KB Partially correct
6 Partially correct 400 ms 548 KB Partially correct
7 Partially correct 441 ms 548 KB Partially correct
8 Partially correct 3 ms 492 KB Partially correct
9 Partially correct 4 ms 500 KB Partially correct
10 Partially correct 1 ms 492 KB Partially correct
11 Partially correct 404 ms 520 KB Partially correct
12 Partially correct 507 ms 576 KB Partially correct
13 Partially correct 834 ms 512 KB Partially correct
14 Partially correct 613 ms 524 KB Partially correct
15 Partially correct 468 ms 532 KB Partially correct
16 Partially correct 394 ms 544 KB Partially correct
17 Partially correct 428 ms 420 KB Partially correct
18 Partially correct 399 ms 528 KB Partially correct
19 Partially correct 402 ms 764 KB Partially correct
20 Partially correct 375 ms 544 KB Partially correct
21 Partially correct 50 ms 600 KB Partially correct
22 Partially correct 64 ms 712 KB Partially correct
23 Partially correct 82 ms 724 KB Partially correct
24 Partially correct 5 ms 620 KB Partially correct
25 Partially correct 3 ms 492 KB Partially correct
26 Partially correct 3 ms 488 KB Partially correct
27 Partially correct 2 ms 492 KB Partially correct
28 Partially correct 1 ms 496 KB Partially correct
29 Partially correct 472 ms 420 KB Partially correct
30 Partially correct 495 ms 420 KB Partially correct
31 Partially correct 491 ms 544 KB Partially correct
32 Partially correct 488 ms 536 KB Partially correct
33 Partially correct 487 ms 528 KB Partially correct
34 Partially correct 307 ms 528 KB Partially correct
35 Partially correct 407 ms 644 KB Partially correct
36 Partially correct 429 ms 624 KB Partially correct
37 Partially correct 463 ms 636 KB Partially correct
38 Partially correct 465 ms 636 KB Partially correct
39 Partially correct 436 ms 724 KB Partially correct
40 Partially correct 441 ms 692 KB Partially correct
41 Partially correct 403 ms 732 KB Partially correct
42 Partially correct 60 ms 672 KB Partially correct
43 Partially correct 105 ms 676 KB Partially correct
44 Partially correct 136 ms 524 KB Partially correct
45 Partially correct 166 ms 544 KB Partially correct
46 Partially correct 314 ms 528 KB Partially correct
47 Partially correct 311 ms 528 KB Partially correct
48 Partially correct 66 ms 748 KB Partially correct
49 Partially correct 59 ms 672 KB Partially correct