답안 #1015490

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1015490 2024-07-06T11:43:06 Z mansur 통행료 (IOI18_highway) C++17
51 / 100
237 ms 262144 KB
#include "highway.h"
#include<bits/stdc++.h>
 
using namespace std;
 
#define rall(s) s.rbegin(), s.rend()
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define s second
#define f first
 
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
 
const int N = 1e6;
 
vector<pii> g[N], s[N], h;
 
void dfs(int u, int id, int dt) {
	s[dt].push_back({u, id});
	for (auto [to, i]: g[u]) {
		if (i == id) continue;
		dfs(to, i, dt + 1);
	}
}
 
void dsf(int u, int id, int dt) {
	if (!dt) {
		h.push_back({id, u});
		return;
	}
	for (auto [to, i]: g[u]) {
 		if (i == id) continue;
		dsf(to, i, dt - 1);
	}
}
 
void find_pair(int n, vector<int> u, vector<int> v, int a, int b) {
	if (sz(u) == 4 && n == 4) {
		answer(1, 3);
		return;
	}
	for (int i = 0; i < sz(u); i++) {
		g[u[i]].push_back({v[i], i});
		g[v[i]].push_back({u[i], i});
	}
	vector<int> w(sz(u));
	ll dt = ask(w);	
	int l = 0, r = sz(u) - 1;
	while (l <= r) {
		int m = (l + r) / 2;
		for (int i = 0; i <= m; i++) w[i] = 1;
		if (ask(w) == dt) l = m + 1;
		else r = m - 1;
		for (int i = 0; i <= m; i++) w[i] = 0;
	}
	int x = u[l], y = v[l];
	dfs(y, l, 1);
	for (int i = 1; i <= n; i++) {
		for (auto [vt, id]: s[i]) {
			w[id] = 1;
		}
	}
	ll diff = ask(w) - dt;
	diff /= b - a;
	for (int i = 1; i <= n; i++) {
		for (auto [vt, id]: s[i]) {
			w[id] = 0;
		}
	}
	int z = diff;
	l = 0, r = sz(s[z]) - 1;
	while (l <= r) {
		int m = (l + r) / 2;
		for (int i = 0; i <= m; i++) {
			w[s[z][i].s] = 1;
		}
		if (ask(w) == dt) l = m + 1;
		else r = m - 1;
		for (int i = 0; i <= m; i++) {
			w[s[z][i].s] = 0;
		}
	}
	x = s[z][l].f;
	dsf(x, -1, dt / a);
	l = 0, r = sz(h) - 1;
	while (l <= r) {
		int m = (l + r) / 2;
		for (int i = 0; i <= m; i++) w[h[i].f] = 1;
		if (ask(w) == dt) l = m + 1;
		else r = m - 1;
		for (int i = 0; i <= m; i++) w[h[i].f] = 0; 
	}
	answer(x, h[l].s);
}
 
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 47192 KB Output is correct
2 Correct 14 ms 47192 KB Output is correct
3 Correct 13 ms 47192 KB Output is correct
4 Correct 13 ms 47272 KB Output is correct
5 Correct 14 ms 47192 KB Output is correct
6 Correct 14 ms 47292 KB Output is correct
7 Correct 13 ms 47192 KB Output is correct
8 Correct 14 ms 47192 KB Output is correct
9 Correct 13 ms 47192 KB Output is correct
10 Correct 13 ms 47192 KB Output is correct
11 Correct 12 ms 47192 KB Output is correct
12 Correct 13 ms 47192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 47448 KB Output is correct
2 Correct 19 ms 47960 KB Output is correct
3 Correct 88 ms 52740 KB Output is correct
4 Correct 93 ms 53660 KB Output is correct
5 Correct 93 ms 54720 KB Output is correct
6 Correct 92 ms 53516 KB Output is correct
7 Correct 98 ms 53620 KB Output is correct
8 Correct 93 ms 53652 KB Output is correct
9 Correct 79 ms 52444 KB Output is correct
10 Correct 93 ms 53584 KB Output is correct
11 Correct 80 ms 53200 KB Output is correct
12 Correct 91 ms 52944 KB Output is correct
13 Correct 91 ms 54532 KB Output is correct
14 Correct 84 ms 52724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 48472 KB Output is correct
2 Correct 27 ms 49744 KB Output is correct
3 Correct 34 ms 49228 KB Output is correct
4 Correct 84 ms 56972 KB Output is correct
5 Correct 77 ms 57204 KB Output is correct
6 Correct 78 ms 58644 KB Output is correct
7 Correct 73 ms 52236 KB Output is correct
8 Correct 78 ms 58260 KB Output is correct
9 Correct 68 ms 54112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 47448 KB Output is correct
2 Correct 19 ms 47960 KB Output is correct
3 Correct 70 ms 52040 KB Output is correct
4 Correct 79 ms 53948 KB Output is correct
5 Correct 70 ms 52440 KB Output is correct
6 Correct 82 ms 53456 KB Output is correct
7 Correct 81 ms 52524 KB Output is correct
8 Correct 76 ms 52676 KB Output is correct
9 Correct 101 ms 52792 KB Output is correct
10 Correct 80 ms 52728 KB Output is correct
11 Correct 84 ms 52736 KB Output is correct
12 Correct 88 ms 55008 KB Output is correct
13 Correct 81 ms 52944 KB Output is correct
14 Correct 88 ms 52996 KB Output is correct
15 Correct 85 ms 53532 KB Output is correct
16 Correct 85 ms 53612 KB Output is correct
17 Correct 83 ms 53040 KB Output is correct
18 Correct 78 ms 52808 KB Output is correct
19 Correct 95 ms 52520 KB Output is correct
20 Correct 85 ms 55260 KB Output is correct
21 Correct 83 ms 54808 KB Output is correct
22 Correct 76 ms 54092 KB Output is correct
23 Correct 87 ms 53780 KB Output is correct
24 Correct 99 ms 54268 KB Output is correct
25 Correct 91 ms 57316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 237 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 228 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -