답안 #241622

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
241622 2020-06-24T20:27:43 Z johutha 경주 (Race) (IOI11_race) C++17
100 / 100
504 ms 107772 KB
#include "race.h"
#include <iostream>
#include <vector>
#include <map>

#define int int64_t

using namespace std;

struct coll
{
	map<int,int>* mp = new map<int,int>();
	int offs = 0;

	bool operator<(const coll& c2)
	{
		return mp->size() < c2.mp->size();
	}

	void insert(int id, int v)
	{
		id -= offs;
		if (mp->find(id) != mp->end()) mp->at(id) = min(v, mp->at(id));
		else mp->insert(make_pair(id, v));
	}

	int query(int k)
	{
		k -= offs;
		if (mp->find(k) == mp->end()) return 1e7;
		return mp->at(k);
	}

	static int check(coll bs, coll nw, int k, int d)
	{
		if (bs < nw) swap(bs, nw);
		int mn = 1e7;

		for (auto p : (*nw.mp))
		{
			int ck = p.first + nw.offs;
			if (k < ck) continue;
			mn = min(mn, bs.query(k - ck) + p.second - 2*d);
		}
		return mn;
	}

	static coll merge(coll bs, coll nw)
	{
		if (bs < nw) swap(bs, nw);

		for (auto p : (*nw.mp))
		{
			bs.insert(p.first + nw.offs, p.second);
		}
		return bs;
	}
};

struct tree
{
	int n, k;
	vector<vector<pair<int,int>>> adjlist;
	int res = 1e7;

	coll dfs(int curr, int par, int d)
	{
		coll rt = coll();
		rt.insert(0, d);

		for (auto p : adjlist[curr])
		{
			if (p.first == par) continue;
			coll nt = dfs(p.first, curr, d + 1);
			nt.offs += p.second;
			res = min(res, coll::check(nt, rt, k, d));
			rt = coll::merge(nt, rt);
		}
		return rt;
	}
};

signed best_path(signed N, signed K, signed H[][2], signed L[])
{
	tree t;
	t.n = N;
	t.k = K;
	t.adjlist.resize(N);

	for (int i = 0; i < N - 1; i++)
	{
		t.adjlist[H[i][0]].emplace_back(H[i][1], L[i]);
		t.adjlist[H[i][1]].emplace_back(H[i][0], L[i]);
	}

	t.dfs(0, -1, 0);
	return (t.res >= N ? -1 : t.res);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 380 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 380 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 640 KB Output is correct
22 Correct 6 ms 768 KB Output is correct
23 Correct 6 ms 768 KB Output is correct
24 Correct 6 ms 768 KB Output is correct
25 Correct 6 ms 768 KB Output is correct
26 Correct 6 ms 768 KB Output is correct
27 Correct 5 ms 640 KB Output is correct
28 Correct 6 ms 768 KB Output is correct
29 Correct 6 ms 768 KB Output is correct
30 Correct 6 ms 768 KB Output is correct
31 Correct 6 ms 768 KB Output is correct
32 Correct 6 ms 768 KB Output is correct
33 Correct 6 ms 768 KB Output is correct
34 Correct 5 ms 640 KB Output is correct
35 Correct 5 ms 640 KB Output is correct
36 Correct 5 ms 640 KB Output is correct
37 Correct 5 ms 640 KB Output is correct
38 Correct 5 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 380 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 149 ms 32248 KB Output is correct
20 Correct 127 ms 32224 KB Output is correct
21 Correct 124 ms 31864 KB Output is correct
22 Correct 139 ms 31480 KB Output is correct
23 Correct 162 ms 44408 KB Output is correct
24 Correct 131 ms 34424 KB Output is correct
25 Correct 114 ms 33784 KB Output is correct
26 Correct 78 ms 42744 KB Output is correct
27 Correct 256 ms 52600 KB Output is correct
28 Correct 314 ms 98040 KB Output is correct
29 Correct 346 ms 95864 KB Output is correct
30 Correct 255 ms 52600 KB Output is correct
31 Correct 239 ms 52600 KB Output is correct
32 Correct 297 ms 52732 KB Output is correct
33 Correct 269 ms 57592 KB Output is correct
34 Correct 390 ms 90384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 380 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 6 ms 640 KB Output is correct
22 Correct 6 ms 768 KB Output is correct
23 Correct 6 ms 768 KB Output is correct
24 Correct 6 ms 768 KB Output is correct
25 Correct 6 ms 768 KB Output is correct
26 Correct 6 ms 768 KB Output is correct
27 Correct 5 ms 640 KB Output is correct
28 Correct 6 ms 768 KB Output is correct
29 Correct 6 ms 768 KB Output is correct
30 Correct 6 ms 768 KB Output is correct
31 Correct 6 ms 768 KB Output is correct
32 Correct 6 ms 768 KB Output is correct
33 Correct 6 ms 768 KB Output is correct
34 Correct 5 ms 640 KB Output is correct
35 Correct 5 ms 640 KB Output is correct
36 Correct 5 ms 640 KB Output is correct
37 Correct 5 ms 640 KB Output is correct
38 Correct 5 ms 640 KB Output is correct
39 Correct 149 ms 32248 KB Output is correct
40 Correct 127 ms 32224 KB Output is correct
41 Correct 124 ms 31864 KB Output is correct
42 Correct 139 ms 31480 KB Output is correct
43 Correct 162 ms 44408 KB Output is correct
44 Correct 131 ms 34424 KB Output is correct
45 Correct 114 ms 33784 KB Output is correct
46 Correct 78 ms 42744 KB Output is correct
47 Correct 256 ms 52600 KB Output is correct
48 Correct 314 ms 98040 KB Output is correct
49 Correct 346 ms 95864 KB Output is correct
50 Correct 255 ms 52600 KB Output is correct
51 Correct 239 ms 52600 KB Output is correct
52 Correct 297 ms 52732 KB Output is correct
53 Correct 269 ms 57592 KB Output is correct
54 Correct 390 ms 90384 KB Output is correct
55 Correct 19 ms 4344 KB Output is correct
56 Correct 13 ms 3200 KB Output is correct
57 Correct 81 ms 29564 KB Output is correct
58 Correct 68 ms 22120 KB Output is correct
59 Correct 115 ms 49016 KB Output is correct
60 Correct 279 ms 96504 KB Output is correct
61 Correct 275 ms 56056 KB Output is correct
62 Correct 228 ms 52600 KB Output is correct
63 Correct 260 ms 52600 KB Output is correct
64 Correct 504 ms 107772 KB Output is correct
65 Correct 470 ms 105720 KB Output is correct
66 Correct 308 ms 91384 KB Output is correct
67 Correct 209 ms 45536 KB Output is correct
68 Correct 364 ms 68856 KB Output is correct
69 Correct 360 ms 73720 KB Output is correct
70 Correct 342 ms 65784 KB Output is correct