답안 #1032776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1032776 2024-07-24T08:25:21 Z AmirAli_H1 통행료 (IOI18_highway) C++17
90 / 100
196 ms 14852 KB
// In the name of Allah

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

typedef		long long int			ll;
typedef		long double				ld;
typedef		pair<int, int>			pii;
typedef		pair<ll, ll>			pll;
typedef		complex<ld>				cld;

#define		all(x)					(x).begin(),(x).end()
#define		len(x)					((ll) (x).size())
#define		F						first
#define		S						second
#define		pb						push_back
#define		sep						' '
#define		endl					'\n'
#define		Mp						make_pair
#define		kill(x)					cout << x << '\n', exit(0)
#define		set_dec(x)				cout << fixed << setprecision(x);
#define		file_io(x,y)			freopen(x, "r", stdin); freopen(y, "w", stdout);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2e5 + 4;
const int oo = 1e9 + 7;

int n, m; ll D;
vector<int> adj[maxn], ls;
vector<pii> E; bool M[maxn];
int arr[maxn], dis[maxn];
queue<int> qu;

void bfs(int v) {
	fill(dis, dis + n, oo);
	dis[v] = 0; qu.push(v);
	while (!qu.empty()) {
		v = qu.front(); qu.pop();
		for (int u : adj[v]) {
			if (dis[v] + 1 < dis[u]) {
				dis[u] = dis[v] + 1;
				qu.push(u);
			}
		}
	}
}

bool cmp(int i, int j) {
	return (dis[i] < dis[j]);
}

ll askx() {
	ls.clear(); ls.resize(m);
	for (int i = 0; i < m; i++) {
		int u = E[i].F, v = E[i].S;
		if (M[u] || M[v]) ls[i] = 1;
		else ls[i] = 0;
	}
	return ask(ls);
}

int getv(vector<int> vc) {
	if (len(vc) == 1) return vc[0];
	
	vector<int> vc1, vc2;
	int mid = (len(vc) / 2);
	for (int i = 0; i < mid; i++) vc1.pb(vc[i]);
	for (int i = mid; i < len(vc); i++) vc2.pb(vc[i]);
	
	for (int u : vc1) M[u] = 1;
	if (askx() == D) return getv(vc2);
	else {
		for (int u : vc1) M[u] = 0;
		return getv(vc1);
	}
}

int getx() {
	iota(arr, arr + n, 0); sort(arr, arr + n, cmp);
	int l = 0, r = n;
	while (r - l > 1) {
		int mid = (l + r) / 2;
		for (int j = 0; j < n; j++) {
			M[arr[j]] = (j >= mid);
		}
		if (askx() > D) l = mid;
		else r = mid;
	}
	return arr[l];
}

void find_pair(int Nx, vector<int> ux, vector<int> vx, int A, int B) {
	n = Nx; m = len(ux);
	for (int i = 0; i < m; i++) {
		int u = ux[i], v = vx[i];
		adj[u].pb(v); adj[v].pb(u);
		E.pb(Mp(u, v));
	}
	D = askx();
	
	vector<int> vc;
	for (int i = 0; i < n; i++) {
		M[i] = 0; vc.pb(i);
	}
	int vr = getv(vc);
	
	bfs(vr); int u1 = getx();
	bfs(u1); int u2 = getx();
	answer(u1, u2);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 3 ms 5024 KB Output is correct
4 Correct 2 ms 4952 KB Output is correct
5 Correct 4 ms 4952 KB Output is correct
6 Correct 2 ms 4952 KB Output is correct
7 Correct 2 ms 5156 KB Output is correct
8 Correct 2 ms 4952 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 2 ms 4952 KB Output is correct
12 Correct 3 ms 5032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5208 KB Output is correct
2 Correct 14 ms 5976 KB Output is correct
3 Correct 130 ms 13192 KB Output is correct
4 Correct 132 ms 13424 KB Output is correct
5 Correct 126 ms 13180 KB Output is correct
6 Correct 105 ms 13412 KB Output is correct
7 Correct 131 ms 13192 KB Output is correct
8 Correct 117 ms 13196 KB Output is correct
9 Correct 126 ms 13200 KB Output is correct
10 Correct 120 ms 13184 KB Output is correct
11 Correct 119 ms 13084 KB Output is correct
12 Correct 132 ms 13092 KB Output is correct
13 Correct 125 ms 13352 KB Output is correct
14 Correct 121 ms 13096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 5976 KB Output is correct
2 Correct 20 ms 6868 KB Output is correct
3 Correct 35 ms 7784 KB Output is correct
4 Correct 89 ms 13096 KB Output is correct
5 Correct 94 ms 13100 KB Output is correct
6 Correct 86 ms 13096 KB Output is correct
7 Correct 83 ms 13104 KB Output is correct
8 Correct 91 ms 13088 KB Output is correct
9 Correct 85 ms 13280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5208 KB Output is correct
2 Correct 13 ms 5976 KB Output is correct
3 Correct 82 ms 11440 KB Output is correct
4 Correct 112 ms 13184 KB Output is correct
5 Correct 107 ms 13460 KB Output is correct
6 Correct 94 ms 13188 KB Output is correct
7 Correct 105 ms 13200 KB Output is correct
8 Correct 113 ms 13348 KB Output is correct
9 Correct 124 ms 13188 KB Output is correct
10 Correct 136 ms 13288 KB Output is correct
11 Correct 129 ms 13096 KB Output is correct
12 Correct 121 ms 13116 KB Output is correct
13 Correct 138 ms 13092 KB Output is correct
14 Correct 130 ms 13088 KB Output is correct
15 Correct 105 ms 13196 KB Output is correct
16 Correct 108 ms 13196 KB Output is correct
17 Correct 117 ms 13336 KB Output is correct
18 Correct 103 ms 13096 KB Output is correct
19 Correct 87 ms 13212 KB Output is correct
20 Correct 108 ms 13092 KB Output is correct
21 Correct 102 ms 13436 KB Output is correct
22 Correct 107 ms 13444 KB Output is correct
23 Correct 102 ms 13432 KB Output is correct
24 Correct 90 ms 13412 KB Output is correct
25 Correct 106 ms 13620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 5976 KB Output is correct
2 Correct 12 ms 5976 KB Output is correct
3 Correct 119 ms 13496 KB Output is correct
4 Correct 124 ms 14092 KB Output is correct
5 Correct 135 ms 14468 KB Output is correct
6 Correct 143 ms 14476 KB Output is correct
7 Correct 155 ms 14472 KB Output is correct
8 Correct 129 ms 14460 KB Output is correct
9 Correct 128 ms 11192 KB Output is correct
10 Correct 134 ms 11540 KB Output is correct
11 Correct 144 ms 11864 KB Output is correct
12 Correct 170 ms 13588 KB Output is correct
13 Correct 140 ms 13956 KB Output is correct
14 Correct 145 ms 14320 KB Output is correct
15 Correct 148 ms 14336 KB Output is correct
16 Correct 132 ms 12224 KB Output is correct
17 Correct 114 ms 13528 KB Output is correct
18 Correct 111 ms 14336 KB Output is correct
19 Correct 98 ms 13576 KB Output is correct
20 Correct 114 ms 13660 KB Output is correct
21 Correct 141 ms 14424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 5976 KB Output is correct
2 Correct 13 ms 5976 KB Output is correct
3 Correct 116 ms 13520 KB Output is correct
4 Partially correct 136 ms 13668 KB Output is partially correct
5 Correct 151 ms 13812 KB Output is correct
6 Partially correct 148 ms 14468 KB Output is partially correct
7 Correct 124 ms 13532 KB Output is correct
8 Correct 133 ms 13648 KB Output is correct
9 Partially correct 134 ms 13816 KB Output is partially correct
10 Partially correct 166 ms 14468 KB Output is partially correct
11 Correct 149 ms 14648 KB Output is correct
12 Partially correct 175 ms 14476 KB Output is partially correct
13 Correct 156 ms 11908 KB Output is correct
14 Correct 139 ms 11516 KB Output is correct
15 Correct 151 ms 11896 KB Output is correct
16 Correct 147 ms 11552 KB Output is correct
17 Correct 146 ms 11912 KB Output is correct
18 Correct 137 ms 11496 KB Output is correct
19 Correct 153 ms 13628 KB Output is correct
20 Correct 143 ms 13860 KB Output is correct
21 Partially correct 175 ms 14324 KB Output is partially correct
22 Correct 163 ms 14308 KB Output is correct
23 Partially correct 179 ms 14332 KB Output is partially correct
24 Partially correct 174 ms 14336 KB Output is partially correct
25 Partially correct 196 ms 14548 KB Output is partially correct
26 Partially correct 164 ms 14328 KB Output is partially correct
27 Correct 114 ms 13612 KB Output is correct
28 Partially correct 123 ms 13524 KB Output is partially correct
29 Partially correct 117 ms 13708 KB Output is partially correct
30 Partially correct 103 ms 13612 KB Output is partially correct
31 Partially correct 110 ms 13584 KB Output is partially correct
32 Partially correct 132 ms 13576 KB Output is partially correct
33 Correct 125 ms 13688 KB Output is correct
34 Correct 123 ms 13584 KB Output is correct
35 Partially correct 109 ms 13572 KB Output is partially correct
36 Partially correct 144 ms 13492 KB Output is partially correct
37 Correct 125 ms 13932 KB Output is correct
38 Partially correct 144 ms 13684 KB Output is partially correct
39 Correct 153 ms 14852 KB Output is correct
40 Partially correct 160 ms 14516 KB Output is partially correct
41 Correct 150 ms 14640 KB Output is correct
42 Correct 166 ms 14420 KB Output is correct