답안 #622524

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
622524 2022-08-04T10:56:57 Z IWTIM 기지국 (IOI20_stations) C++14
100 / 100
1070 ms 14944 KB
# include "stations.h"
# include <bits/stdc++.h>
using namespace std;
using namespace std;
using namespace std;
using ll = long long;
using db = long double; // or double, if TL is tight
using str = string; // yay python! 
 
// pairs
using pii = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;
#define mp make_pair
#define f first
#define s second
 
#define tcT template<class T
#define tcTU tcT, class U
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>; 
tcT, size_t SZ> using AR = array<T,SZ>; 
using vi = V<int>;
using vb = V<bool>;
using vl = V<ll>;
using vd = V<db>;
using vs = V<str>;
using vpi = V<pii>;
using vpl = V<pl>;
using vpd = V<pd>;
 
// vectors
// oops size(x), rbegin(x), rend(x) need C++17
#define sz(x) int((x).size())
#define f first
#define s second
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend() 
#define sor(x) sort(all(x)) 
#define rsz resize
#define ins insert 
#define pb push_back
#define eb emplace_back
#define ft front()
#define bk back()
 
#define lb lower_bound
#define ub upper_bound
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define rep(a) F0R(_,a)
#define each(a,x) for (auto& a: x)
const int MOD = 998244353;
const int MX = 2e5+5;
const ll BIG = 1e18; // not too close to LLONG_MAX
const db PI = acos((db)-1);
const int dx[4]{1,0,-1,0}, dy[4]{0,1,0,-1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;
struct DSU {
	vi e; void init(int N) { e = vi(N,-1); }
	int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); } 
	bool sameSet(int a, int b) { return get(a) == get(b); }
	int size(int x) { return -e[get(x)]; }
	bool unite(int x, int y) { // union by size
		x = get(x), y = get(y); if (x == y) return 0;
		if (e[x] > e[y]) swap(x,y);
		e[x] += e[y]; e[y] = x; return 1;
	}
};
/*
inline namespace Helpers {
	//////////// is_iterable
	// https://stackoverflow.com/questions/13830158/check-if-a-variable-type-is-iterable
	// this gets used only when we can call begin() and end() on that type
	tcT, class = void> struct is_iterable : false_type {};
	tcT> struct is_iterable<T, void_t<decltype(begin(declval<T>())),
	                                  decltype(end(declval<T>()))
	                                 >
	                       > : true_type {};
	tcT> constexpr bool is_iterable_v = is_iterable<T>::value;
 
	//////////// is_readable
	tcT, class = void> struct is_readable : false_type {};
	tcT> struct is_readable<T,
	        typename std::enable_if_t<
	            is_same_v<decltype(cin >> declval<T&>()), istream&>
	        >
	    > : true_type {};
	tcT> constexpr bool is_readable_v = is_readable<T>::value;
 
	//////////// is_printable
	// // https://nafe.es/posts/2020-02-29-is-printable/
	tcT, class = void> struct is_printable : false_type {};
	tcT> struct is_printable<T,
	        typename std::enable_if_t<
	            is_same_v<decltype(cout << declval<T>()), ostream&>
	        >
	    > : true_type {};
	tcT> constexpr bool is_printable_v = is_printable<T>::value;
}*/
const int N = 3e5 + 5;
int lv[N],tin,in[N],out[N];
vector <int> g[N];
void dfs(int a, int p) {
	lv[a] = (p == -1 ? 1 : (lv[p] + 1));
	tin++;
	in[a] = tin;
	for (int to : g[a]) {
		if (to == p) continue;
		dfs(to,a);
	}
	tin++;
	out[a] = tin;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
	vector <int> labels = vector <int> (n, 0);
	tin = 0;
	for (int i = 0; i < n; i++) {
		g[i].clear();
	}
	for (int i = 0; i < u.size(); i++) {
		int a = u[i];
		int b = v[i];
		g[a].pb(b);
		g[b].pb(a);
	}
	dfs(0, -1);
	vector <pii> vv;
	for (int i = 0; i < n; i++) {
		labels[i] = ((lv[i] % 2 == 1) ? in[i] : out[i]);
		vv.pb({labels[i], i});
	}
	sort(vv.begin(),vv.end());
	for (int i = 0; i < n; i++) {
		labels[vv[i].s] = i;
	}
	return labels;
}
int upper(int in, int out, int x) {
	return (in <= x && out >= x);
}
int find_next_station(int s, int t, std::vector<int> c) {
	if (c.size() == 1) {
		return c[0];
	}
	if (c[0] > s) {
		// lv[s] % 2 == 1  ( in[i] ) 
		// first child's IN = s + 1, OUT = c[0]
		if (upper(s + 1,c[0], t)) return c[0];
		for (int i = 1; i < (int)c.size() - 1; i++) {
			int in = c[i - 1] + 1;
			int out = c[i];
			if (upper(in,out, t)) return c[i];
		}
		return c.back();
 	}
 	if (c[0] < s) {
 		// lv[s] % 2 == 0 ( OUT[i] ) 
 		// last child's OUT = s - 1, in = c.back();
 		if (upper(c.back(), s - 1, t)) return c.back();
 		for (int i = (int)c.size() - 2; i >= 1; i--) {
 			int out = c[i + 1] - 1;
 			int in = c[i];
 			if (upper(in, out,t)) return c[i];
		 }
		 return c[0];
	 }
}

Compilation message

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:125:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |  for (int i = 0; i < u.size(); i++) {
      |                  ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:172:1: warning: control reaches end of non-void function [-Wreturn-type]
  172 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 531 ms 14624 KB Output is correct
2 Correct 390 ms 14648 KB Output is correct
3 Correct 956 ms 14600 KB Output is correct
4 Correct 786 ms 14588 KB Output is correct
5 Correct 468 ms 14608 KB Output is correct
6 Correct 531 ms 14740 KB Output is correct
7 Correct 616 ms 14596 KB Output is correct
8 Correct 10 ms 14596 KB Output is correct
9 Correct 12 ms 14604 KB Output is correct
10 Correct 7 ms 14596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 417 ms 14608 KB Output is correct
2 Correct 684 ms 14600 KB Output is correct
3 Correct 1070 ms 14496 KB Output is correct
4 Correct 740 ms 14656 KB Output is correct
5 Correct 565 ms 14496 KB Output is correct
6 Correct 439 ms 14596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 549 ms 14628 KB Output is correct
2 Correct 520 ms 14624 KB Output is correct
3 Correct 910 ms 14596 KB Output is correct
4 Correct 793 ms 14604 KB Output is correct
5 Correct 573 ms 14608 KB Output is correct
6 Correct 471 ms 14632 KB Output is correct
7 Correct 426 ms 14624 KB Output is correct
8 Correct 9 ms 14596 KB Output is correct
9 Correct 11 ms 14524 KB Output is correct
10 Correct 8 ms 14660 KB Output is correct
11 Correct 633 ms 14496 KB Output is correct
12 Correct 399 ms 14836 KB Output is correct
13 Correct 478 ms 14800 KB Output is correct
14 Correct 424 ms 14604 KB Output is correct
15 Correct 61 ms 14700 KB Output is correct
16 Correct 72 ms 14676 KB Output is correct
17 Correct 103 ms 14624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 894 ms 14588 KB Output is correct
2 Correct 590 ms 14600 KB Output is correct
3 Correct 632 ms 14604 KB Output is correct
4 Correct 8 ms 14600 KB Output is correct
5 Correct 10 ms 14600 KB Output is correct
6 Correct 8 ms 14596 KB Output is correct
7 Correct 634 ms 14608 KB Output is correct
8 Correct 800 ms 14596 KB Output is correct
9 Correct 549 ms 14496 KB Output is correct
10 Correct 575 ms 14628 KB Output is correct
11 Correct 10 ms 14596 KB Output is correct
12 Correct 11 ms 14596 KB Output is correct
13 Correct 11 ms 14604 KB Output is correct
14 Correct 9 ms 14596 KB Output is correct
15 Correct 8 ms 14716 KB Output is correct
16 Correct 535 ms 14496 KB Output is correct
17 Correct 499 ms 14500 KB Output is correct
18 Correct 515 ms 14604 KB Output is correct
19 Correct 495 ms 14604 KB Output is correct
20 Correct 460 ms 14500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 516 ms 14624 KB Output is correct
2 Correct 442 ms 14736 KB Output is correct
3 Correct 916 ms 14596 KB Output is correct
4 Correct 701 ms 14600 KB Output is correct
5 Correct 653 ms 14604 KB Output is correct
6 Correct 403 ms 14628 KB Output is correct
7 Correct 418 ms 14608 KB Output is correct
8 Correct 9 ms 14596 KB Output is correct
9 Correct 10 ms 14596 KB Output is correct
10 Correct 10 ms 14640 KB Output is correct
11 Correct 403 ms 14624 KB Output is correct
12 Correct 504 ms 14604 KB Output is correct
13 Correct 895 ms 14596 KB Output is correct
14 Correct 646 ms 14496 KB Output is correct
15 Correct 628 ms 14608 KB Output is correct
16 Correct 406 ms 14628 KB Output is correct
17 Correct 585 ms 14500 KB Output is correct
18 Correct 417 ms 14832 KB Output is correct
19 Correct 416 ms 14944 KB Output is correct
20 Correct 382 ms 14628 KB Output is correct
21 Correct 54 ms 14528 KB Output is correct
22 Correct 72 ms 14696 KB Output is correct
23 Correct 105 ms 14652 KB Output is correct
24 Correct 10 ms 14596 KB Output is correct
25 Correct 12 ms 14596 KB Output is correct
26 Correct 10 ms 14596 KB Output is correct
27 Correct 9 ms 14600 KB Output is correct
28 Correct 8 ms 14596 KB Output is correct
29 Correct 531 ms 14596 KB Output is correct
30 Correct 542 ms 14604 KB Output is correct
31 Correct 429 ms 14496 KB Output is correct
32 Correct 542 ms 14496 KB Output is correct
33 Correct 530 ms 14604 KB Output is correct
34 Correct 286 ms 14728 KB Output is correct
35 Correct 416 ms 14848 KB Output is correct
36 Correct 415 ms 14724 KB Output is correct
37 Correct 420 ms 14812 KB Output is correct
38 Correct 477 ms 14720 KB Output is correct
39 Correct 393 ms 14776 KB Output is correct
40 Correct 484 ms 14832 KB Output is correct
41 Correct 414 ms 14836 KB Output is correct
42 Correct 66 ms 14652 KB Output is correct
43 Correct 102 ms 14624 KB Output is correct
44 Correct 133 ms 14624 KB Output is correct
45 Correct 154 ms 14736 KB Output is correct
46 Correct 268 ms 14756 KB Output is correct
47 Correct 245 ms 14624 KB Output is correct
48 Correct 72 ms 14780 KB Output is correct
49 Correct 58 ms 14928 KB Output is correct