Submission #430491

# Submission time Handle Problem Language Result Execution time Memory
430491 2021-06-16T14:38:33 Z alishahali1382 Stations (IOI20_stations) C++14
76 / 100
1267 ms 848 KB
#include "stations.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
#define debug(x) {cerr<<#x<<"="<<x<<"\n";}
#define debug2(x, y) {cerr<<"{"<<#x<<", "<<#y<<"}={"<<x<<", "<<y<<"}\n";}
#define debugp(p) {cerr<<#p<<"={"<<p.first<<", "<<p.second<<"}\n";}
#define debugv(abcd) {cerr<<#abcd<<": "; for (auto dcba:abcd) cerr<<dcba<<", ";cerr<<"\n";}
#define pb push_back
#define all(x) x.begin(), x.end()
#define SZ(x) ((int)x.size())

const int inf=1000000100; // 1e9
const ll INF=10000000001000000; // 1e16
const int mod=1000000007;
const int MAXN=1010;

int n, m, k, x, y, a, b, t, ans;
int stt[MAXN], fnt[MAXN], h[MAXN], timer;
vi G[MAXN];

void dfs(int node, int par){
	stt[node]=timer++;
	for (int v:G[node]) if (v!=par){
		h[v]=h[node]+1;
		dfs(v, node);
	}
	fnt[node]=timer++;
}

vi label(int _n, int _k, vi U, vi V){
	n=_n;
	k=_k;
	vi out(n);
	for (int i=0; i<n; i++) G[i].clear();
	for (int i=0; i<n-1; i++){
		int u=U[i], v=V[i];
		G[u].pb(v);
		G[v].pb(u);
	}
	timer=0;
	dfs(0, 0);
	for (int i=0; i<n; i++){
		if (h[i]&1) out[i]=fnt[i];
		else out[i]=stt[i];
	}
	vi comp=out;
	sort(all(comp));
	// for (int i=0; i<n; i++) out[i]=lower_bound(all(comp), out[i])-comp.begin();
	return out;
}

int find_next_station(int s, int t, vi adj){
	// cerr<<"\n";
	// debug2(s, t)
	for (int x:adj) if (x==t) return x;
	if (SZ(adj)==1) return adj[0];
	sort(all(adj));
	if (s<adj[0]){
		// stt
		int par=-1;
		if (s){
			par=adj.back();
			adj.pop_back();
		}
		int stt_s=s, fnt_s=adj.back()+1;
		if (t<stt_s || fnt_s<t) return par;
		return *lower_bound(all(adj), t);
	}
	// fnt
	assert(adj.back()<s);
	int par=adj[0];
	reverse(all(adj));
	adj.pop_back();
	
	int stt_s=adj.back()-1, fnt_s=s;
	if (t<stt_s || fnt_s<t) return par;
	while (SZ(adj)>1){
		int v=adj.back();
		adj.pop_back();
		if (adj.back()<t) continue ;
		return v;
	}
	return adj.back();
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 416 KB Invalid labels (values out of range). scenario=2, k=1000, vertex=1, label=1990
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 292 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1022
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 697 ms 648 KB Output is correct
2 Correct 683 ms 636 KB Output is correct
3 Correct 1045 ms 516 KB Output is correct
4 Correct 787 ms 528 KB Output is correct
5 Correct 912 ms 400 KB Output is correct
6 Correct 531 ms 648 KB Output is correct
7 Correct 520 ms 528 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 6 ms 596 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 705 ms 400 KB Output is correct
12 Correct 565 ms 760 KB Output is correct
13 Correct 642 ms 732 KB Output is correct
14 Correct 506 ms 532 KB Output is correct
15 Correct 93 ms 528 KB Output is correct
16 Correct 60 ms 528 KB Output is correct
17 Correct 157 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1015 ms 644 KB Output is correct
2 Correct 887 ms 600 KB Output is correct
3 Correct 839 ms 508 KB Output is correct
4 Correct 4 ms 596 KB Output is correct
5 Correct 4 ms 596 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 563 ms 512 KB Output is correct
8 Correct 1142 ms 640 KB Output is correct
9 Correct 837 ms 572 KB Output is correct
10 Correct 786 ms 656 KB Output is correct
11 Correct 6 ms 464 KB Output is correct
12 Correct 8 ms 468 KB Output is correct
13 Correct 7 ms 596 KB Output is correct
14 Correct 5 ms 464 KB Output is correct
15 Correct 2 ms 596 KB Output is correct
16 Correct 732 ms 528 KB Output is correct
17 Correct 784 ms 400 KB Output is correct
18 Correct 653 ms 508 KB Output is correct
19 Correct 576 ms 400 KB Output is correct
20 Correct 560 ms 528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 722 ms 636 KB Partially correct
2 Partially correct 511 ms 632 KB Partially correct
3 Correct 1218 ms 508 KB Output is correct
4 Correct 716 ms 400 KB Output is correct
5 Correct 660 ms 516 KB Output is correct
6 Partially correct 564 ms 636 KB Partially correct
7 Partially correct 558 ms 520 KB Partially correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Partially correct 706 ms 520 KB Partially correct
12 Partially correct 572 ms 528 KB Partially correct
13 Correct 1267 ms 504 KB Output is correct
14 Correct 903 ms 500 KB Output is correct
15 Correct 779 ms 528 KB Output is correct
16 Partially correct 605 ms 708 KB Partially correct
17 Correct 871 ms 512 KB Output is correct
18 Partially correct 597 ms 640 KB Partially correct
19 Partially correct 593 ms 848 KB Partially correct
20 Partially correct 608 ms 600 KB Partially correct
21 Correct 58 ms 576 KB Output is correct
22 Partially correct 79 ms 728 KB Partially correct
23 Partially correct 123 ms 712 KB Partially correct
24 Correct 9 ms 596 KB Output is correct
25 Correct 4 ms 464 KB Output is correct
26 Correct 6 ms 468 KB Output is correct
27 Correct 5 ms 596 KB Output is correct
28 Correct 2 ms 600 KB Output is correct
29 Correct 811 ms 636 KB Output is correct
30 Correct 523 ms 648 KB Output is correct
31 Correct 741 ms 512 KB Output is correct
32 Correct 617 ms 508 KB Output is correct
33 Correct 578 ms 616 KB Output is correct
34 Partially correct 368 ms 608 KB Partially correct
35 Partially correct 456 ms 708 KB Partially correct
36 Partially correct 701 ms 808 KB Partially correct
37 Partially correct 547 ms 700 KB Partially correct
38 Partially correct 618 ms 700 KB Partially correct
39 Partially correct 677 ms 740 KB Partially correct
40 Partially correct 537 ms 700 KB Partially correct
41 Partially correct 621 ms 732 KB Partially correct
42 Partially correct 57 ms 640 KB Partially correct
43 Partially correct 165 ms 656 KB Partially correct
44 Partially correct 207 ms 612 KB Partially correct
45 Partially correct 266 ms 600 KB Partially correct
46 Partially correct 431 ms 556 KB Partially correct
47 Partially correct 346 ms 528 KB Partially correct
48 Partially correct 86 ms 784 KB Partially correct
49 Partially correct 82 ms 676 KB Partially correct