답안 #1072069

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072069 2024-08-23T13:56:29 Z Joshua_Andersson 통행료 (IOI18_highway) C++14
100 / 100
213 ms 13124 KB
#include "highway.h"

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll linf = ll(1e18);

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> p2;

#define rep(i, high) for (int i = 0; i < high; i++)
#define repp(i, low, high) for (int i = low; i < high; i++)
#define repe(i, container) for (auto& i : container)
#define sz(container) ((int)container.size())
#define all(x) begin(x),end(x)

#if _LOCAL
#define assert(x) if (!(x)) __debugbreak()
#endif

typedef long long ll;

void dfs(int u, int p, int v, int d, int sign, vector<vector<p2>>&edges, vi& edgedist, vi& nodedist)
{
	nodedist[u] = d;
	repe(e, edges[u])
	{
		if (e.first == p) continue;
		edgedist[e.second] = d*sign * (e.first == v ? -1 : 1);
		dfs(e.first, u, v, d + 1, sign * (e.first==v?-1:1), edges, edgedist, nodedist);
	}
}

void find_pair(int n, std::vector<int> U, std::vector<int> V, int A, int B)
{
	int m = sz(U);

	ll baseline = ask(vi(m, 0));

	int lo = -1;
	int hi = m;
	while (lo+1<hi)
	{
		int mid = (lo + hi) / 2;
		vi w(m);
		rep(i, mid + 1) w[i] = 1;
		if (ask(w) > baseline)
		{
			hi = mid;
		}
		else lo = mid;
	}

	int u = U[hi];
	int v = V[hi];
	vector<vector<p2>> edges(n);
	rep(i, m)
	{
		int a = U[i];
		int b = V[i];
		edges[a].emplace_back(b, i);
		edges[b].emplace_back(a, i);
	}
	
	vi ans;

	rep(_, 2)
	{
		vi istree(m);
		vi edgedist(m);
		vi nodedist(n);
		priority_queue<tuple<int,int,int>> q;
		vi vis(n);

		q.emplace(-1, -1, u);
		while (sz(q))
		{
			int d, s, a;
			tie(d, s, a) = q.top();
			q.pop();

			nodedist[a] = -d*s;
			repe(e, edges[a])
			{
				if (vis[e.first])
				{
					if (edgedist[e.second]==0)
					{
						edgedist[e.second] = -int(1e7);
					}
					//
				}
				else
				{
					vis[e.first] = 1;
					istree[e.second] = 1;
					edgedist[e.second] = -d * s * (e.first == v ? -1 : 1);
					q.emplace(d - 1, s * (e.first == v ? -1 : 1), e.first);
				}
			}
		}
		nodedist[u] = -int(1e6);

		vector<p2> edge_order;
		rep(i, m) edge_order.emplace_back(edgedist[i], i);
		sort(edge_order.rbegin(), edge_order.rend());

		lo = -1;
		hi = n;
		for (int i = m-1; i >= 0; i--) if (edge_order[i].first < 0) hi = i;
		while (lo+1<hi)
		{
			int mid = (lo + hi) / 2;
			vi w(m);
			rep(i, m)
			{
				if (!istree[i]) w[i] = 1;
			}
			rep(i, mid + 1) w[edge_order[i].second] = 1;
			if (ask(w) > baseline)
			{
				hi = mid;
			}
			else lo = mid;
		}
		rep(i, m)
		{
			if (_==1)
			{
				int e = edge_order[i].second;
				int k = nodedist[U[e]] > nodedist[V[e]] ? U[e] : V[e];
				if (k== 42568||U[e]== 42568||V[e]== 42568)
				{
					cout << "";
				}
			}
		}
		int e = edge_order[hi].second;
		ans.push_back(nodedist[U[e]]>nodedist[V[e]]?U[e]:V[e]);
		swap(u, v);
	}
	

	answer(ans[0], ans[1]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 412 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 13 ms 1544 KB Output is correct
3 Correct 122 ms 10564 KB Output is correct
4 Correct 118 ms 10484 KB Output is correct
5 Correct 125 ms 10752 KB Output is correct
6 Correct 112 ms 10536 KB Output is correct
7 Correct 124 ms 10632 KB Output is correct
8 Correct 118 ms 10468 KB Output is correct
9 Correct 118 ms 10688 KB Output is correct
10 Correct 118 ms 10632 KB Output is correct
11 Correct 112 ms 9920 KB Output is correct
12 Correct 102 ms 9920 KB Output is correct
13 Correct 122 ms 9916 KB Output is correct
14 Correct 108 ms 9920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1368 KB Output is correct
2 Correct 21 ms 2560 KB Output is correct
3 Correct 24 ms 3496 KB Output is correct
4 Correct 74 ms 9920 KB Output is correct
5 Correct 75 ms 9920 KB Output is correct
6 Correct 77 ms 10152 KB Output is correct
7 Correct 70 ms 9924 KB Output is correct
8 Correct 76 ms 9916 KB Output is correct
9 Correct 77 ms 10088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 13 ms 1784 KB Output is correct
3 Correct 89 ms 8524 KB Output is correct
4 Correct 139 ms 10344 KB Output is correct
5 Correct 131 ms 10636 KB Output is correct
6 Correct 116 ms 10628 KB Output is correct
7 Correct 131 ms 10668 KB Output is correct
8 Correct 113 ms 10628 KB Output is correct
9 Correct 122 ms 10640 KB Output is correct
10 Correct 122 ms 10668 KB Output is correct
11 Correct 108 ms 9920 KB Output is correct
12 Correct 108 ms 9916 KB Output is correct
13 Correct 128 ms 10068 KB Output is correct
14 Correct 112 ms 9808 KB Output is correct
15 Correct 120 ms 10648 KB Output is correct
16 Correct 111 ms 10616 KB Output is correct
17 Correct 112 ms 9968 KB Output is correct
18 Correct 122 ms 10160 KB Output is correct
19 Correct 107 ms 10684 KB Output is correct
20 Correct 102 ms 9912 KB Output is correct
21 Correct 104 ms 12076 KB Output is correct
22 Correct 99 ms 12200 KB Output is correct
23 Correct 113 ms 11412 KB Output is correct
24 Correct 112 ms 11292 KB Output is correct
25 Correct 104 ms 10108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 1908 KB Output is correct
2 Correct 14 ms 1720 KB Output is correct
3 Correct 135 ms 11292 KB Output is correct
4 Correct 161 ms 12028 KB Output is correct
5 Correct 176 ms 13112 KB Output is correct
6 Correct 207 ms 13104 KB Output is correct
7 Correct 182 ms 13112 KB Output is correct
8 Correct 199 ms 13120 KB Output is correct
9 Correct 128 ms 10096 KB Output is correct
10 Correct 123 ms 10312 KB Output is correct
11 Correct 132 ms 11236 KB Output is correct
12 Correct 196 ms 12284 KB Output is correct
13 Correct 184 ms 12712 KB Output is correct
14 Correct 193 ms 13100 KB Output is correct
15 Correct 188 ms 13100 KB Output is correct
16 Correct 148 ms 10924 KB Output is correct
17 Correct 104 ms 12204 KB Output is correct
18 Correct 109 ms 12436 KB Output is correct
19 Correct 107 ms 12352 KB Output is correct
20 Correct 112 ms 12396 KB Output is correct
21 Correct 171 ms 12732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 1864 KB Output is correct
2 Correct 15 ms 1708 KB Output is correct
3 Correct 152 ms 11564 KB Output is correct
4 Correct 173 ms 11572 KB Output is correct
5 Correct 152 ms 11872 KB Output is correct
6 Correct 193 ms 13104 KB Output is correct
7 Correct 139 ms 11248 KB Output is correct
8 Correct 141 ms 11584 KB Output is correct
9 Correct 162 ms 11876 KB Output is correct
10 Correct 187 ms 13124 KB Output is correct
11 Correct 201 ms 13124 KB Output is correct
12 Correct 186 ms 13108 KB Output is correct
13 Correct 144 ms 11192 KB Output is correct
14 Correct 123 ms 10276 KB Output is correct
15 Correct 152 ms 11028 KB Output is correct
16 Correct 125 ms 10260 KB Output is correct
17 Correct 128 ms 11220 KB Output is correct
18 Correct 117 ms 10276 KB Output is correct
19 Correct 189 ms 12272 KB Output is correct
20 Correct 181 ms 13116 KB Output is correct
21 Correct 186 ms 13104 KB Output is correct
22 Correct 213 ms 13080 KB Output is correct
23 Correct 181 ms 13104 KB Output is correct
24 Correct 183 ms 13108 KB Output is correct
25 Correct 188 ms 13116 KB Output is correct
26 Correct 179 ms 13096 KB Output is correct
27 Correct 111 ms 12360 KB Output is correct
28 Correct 111 ms 12192 KB Output is correct
29 Correct 105 ms 12552 KB Output is correct
30 Correct 107 ms 12948 KB Output is correct
31 Correct 105 ms 12312 KB Output is correct
32 Correct 109 ms 12364 KB Output is correct
33 Correct 117 ms 12392 KB Output is correct
34 Correct 128 ms 12308 KB Output is correct
35 Correct 121 ms 12684 KB Output is correct
36 Correct 114 ms 12196 KB Output is correct
37 Correct 111 ms 12416 KB Output is correct
38 Correct 116 ms 12344 KB Output is correct
39 Correct 163 ms 12728 KB Output is correct
40 Correct 189 ms 12768 KB Output is correct
41 Correct 190 ms 12716 KB Output is correct
42 Correct 186 ms 12736 KB Output is correct