답안 #835053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
835053 2023-08-23T07:08:34 Z arnold518 통행료 (IOI18_highway) C++17
90 / 100
192 ms 11400 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int MAXN = 9e4;
const int MAXM = 13e4;

int N, M, S, T;
ll A, B, D;
pii E[MAXM+10];
vector<int> adj[MAXN+10];

int vis[MAXN+10];
int P[MAXN+10], PP[MAXN+10];

int TT[MAXM+10];
ll query()
{
	vector<int> V;
	//for(int i=1; i<=M; i++) printf("%d ", TT[i]); printf("\n");
	for(int i=0; i<M; i++) V.push_back(TT[i+1]);
	return ask(V);
}

void find_pair(int _N, vector<int> _U, vector<int> _V, int _A, int _B)
{
	N=_N; M=_U.size();
	for(int i=1; i<=M; i++) E[i]={_U[i-1]+1, _V[i-1]+1};
	for(int i=1; i<=M; i++)
	{
		adj[E[i].first].push_back(E[i].second);
		adj[E[i].second].push_back(E[i].first);
	}
	A=_A; B=_B;

	for(int i=1; i<=M; i++) TT[i]=0;
	D=query()/A;

	int lo=0, hi=M;
	while(lo+1<hi)
	{
		int mid=lo+hi>>1;
		for(int i=1; i<=M; i++) TT[i]=0;
		for(int i=1; i<=mid; i++) TT[i]=1;
		if(D*A!=query()) hi=mid;
		else lo=mid;
	}

	int cnt=1;
	queue<int> Q;
	Q.push(E[hi].first); vis[E[hi].first]=true;
	Q.push(E[hi].second); vis[E[hi].second]=true;

	//printf("%d %d\n", E[hi].first, E[hi].second);

	while(!Q.empty())
	{
		int now=Q.front(); Q.pop();
		P[now]=cnt++;
		for(auto nxt : adj[now])
		{
			if(vis[nxt]) continue;
			vis[nxt]=true;
			Q.push(nxt);
		}
	}
	for(int i=1; i<=N; i++) PP[P[i]]=i;

	lo=0, hi=N;
	while(lo+1<hi)
	{
		int mid=lo+hi>>1;
		for(int i=1; i<=M; i++)
		{
			auto [u, v]=E[i];
			if(P[u]<=mid && P[v]<=mid) TT[i]=0;
			else TT[i]=1;
		}
		if(D*A!=query()) lo=mid;
		else hi=mid;
	}
	T=PP[hi];
	//printf("%d\n", T);

	cnt=1;
	for(int i=1; i<=N; i++) vis[i]=0;
	Q.push(T); vis[T]=true;
	while(!Q.empty())
	{
		int now=Q.front(); Q.pop();
		P[now]=cnt++;
		for(auto nxt : adj[now])
		{
			if(vis[nxt]) continue;
			vis[nxt]=true;
			Q.push(nxt);
		}
	}
	for(int i=1; i<=N; i++) PP[P[i]]=i;

	lo=0, hi=N;
	while(lo+1<hi)
	{
		int mid=lo+hi>>1;
		for(int i=1; i<=M; i++)
		{
			auto [u, v]=E[i];
			if(P[u]<=mid && P[v]<=mid) TT[i]=0;
			else TT[i]=1;
		}
		if(D*A!=query()) lo=mid;
		else hi=mid;
	}
	S=PP[hi];

	//printf("!%d %d\n", S, T);
	answer(S-1, T-1);
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:46:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |   int mid=lo+hi>>1;
      |           ~~^~~
highway.cpp:76:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   76 |   int mid=lo+hi>>1;
      |           ~~^~~
highway.cpp:108:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  108 |   int mid=lo+hi>>1;
      |           ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 2 ms 2432 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2508 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 2 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2512 KB Output is correct
2 Correct 15 ms 3152 KB Output is correct
3 Correct 115 ms 9804 KB Output is correct
4 Correct 105 ms 9780 KB Output is correct
5 Correct 159 ms 9764 KB Output is correct
6 Correct 123 ms 9916 KB Output is correct
7 Correct 99 ms 9812 KB Output is correct
8 Correct 102 ms 9780 KB Output is correct
9 Correct 121 ms 9852 KB Output is correct
10 Correct 104 ms 9768 KB Output is correct
11 Correct 98 ms 9632 KB Output is correct
12 Correct 114 ms 9668 KB Output is correct
13 Correct 125 ms 9672 KB Output is correct
14 Correct 101 ms 9684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 3152 KB Output is correct
2 Correct 22 ms 4048 KB Output is correct
3 Correct 24 ms 4772 KB Output is correct
4 Correct 82 ms 9752 KB Output is correct
5 Correct 80 ms 9688 KB Output is correct
6 Correct 77 ms 9628 KB Output is correct
7 Correct 83 ms 9652 KB Output is correct
8 Correct 78 ms 9708 KB Output is correct
9 Correct 85 ms 9636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2512 KB Output is correct
2 Correct 23 ms 3144 KB Output is correct
3 Correct 70 ms 8336 KB Output is correct
4 Correct 100 ms 9812 KB Output is correct
5 Correct 92 ms 9828 KB Output is correct
6 Correct 92 ms 9792 KB Output is correct
7 Correct 137 ms 9840 KB Output is correct
8 Correct 88 ms 9820 KB Output is correct
9 Correct 129 ms 9796 KB Output is correct
10 Correct 119 ms 9820 KB Output is correct
11 Correct 110 ms 9664 KB Output is correct
12 Correct 111 ms 9660 KB Output is correct
13 Correct 106 ms 9664 KB Output is correct
14 Correct 146 ms 9636 KB Output is correct
15 Correct 102 ms 9784 KB Output is correct
16 Correct 87 ms 9780 KB Output is correct
17 Correct 121 ms 9636 KB Output is correct
18 Correct 108 ms 9640 KB Output is correct
19 Correct 103 ms 9776 KB Output is correct
20 Correct 94 ms 9644 KB Output is correct
21 Correct 84 ms 10112 KB Output is correct
22 Correct 80 ms 10108 KB Output is correct
23 Correct 93 ms 10272 KB Output is correct
24 Correct 86 ms 10020 KB Output is correct
25 Correct 107 ms 9704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 3280 KB Output is correct
2 Correct 22 ms 3324 KB Output is correct
3 Correct 117 ms 10140 KB Output is correct
4 Correct 137 ms 10640 KB Output is correct
5 Correct 147 ms 11344 KB Output is correct
6 Correct 165 ms 11228 KB Output is correct
7 Correct 152 ms 11256 KB Output is correct
8 Correct 145 ms 11292 KB Output is correct
9 Correct 145 ms 9076 KB Output is correct
10 Correct 129 ms 9692 KB Output is correct
11 Correct 124 ms 9480 KB Output is correct
12 Correct 141 ms 10760 KB Output is correct
13 Correct 166 ms 11040 KB Output is correct
14 Correct 177 ms 11200 KB Output is correct
15 Correct 137 ms 11116 KB Output is correct
16 Correct 142 ms 9860 KB Output is correct
17 Correct 107 ms 10196 KB Output is correct
18 Correct 97 ms 10248 KB Output is correct
19 Correct 126 ms 10248 KB Output is correct
20 Correct 103 ms 10356 KB Output is correct
21 Correct 134 ms 11116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 3280 KB Output is correct
2 Correct 11 ms 3340 KB Output is correct
3 Correct 105 ms 10168 KB Output is correct
4 Correct 136 ms 10408 KB Output is correct
5 Correct 147 ms 10636 KB Output is correct
6 Partially correct 160 ms 11236 KB Output is partially correct
7 Partially correct 112 ms 10184 KB Output is partially correct
8 Partially correct 192 ms 10324 KB Output is partially correct
9 Partially correct 132 ms 10576 KB Output is partially correct
10 Partially correct 152 ms 11268 KB Output is partially correct
11 Partially correct 144 ms 11204 KB Output is partially correct
12 Partially correct 153 ms 11224 KB Output is partially correct
13 Correct 122 ms 9556 KB Output is correct
14 Correct 145 ms 9440 KB Output is correct
15 Correct 138 ms 9452 KB Output is correct
16 Correct 129 ms 9404 KB Output is correct
17 Correct 129 ms 9488 KB Output is correct
18 Correct 123 ms 9484 KB Output is correct
19 Correct 134 ms 10648 KB Output is correct
20 Correct 188 ms 10872 KB Output is correct
21 Partially correct 139 ms 11096 KB Output is partially correct
22 Partially correct 146 ms 11148 KB Output is partially correct
23 Partially correct 138 ms 11136 KB Output is partially correct
24 Partially correct 174 ms 11128 KB Output is partially correct
25 Partially correct 145 ms 11144 KB Output is partially correct
26 Correct 148 ms 11160 KB Output is correct
27 Partially correct 97 ms 10260 KB Output is partially correct
28 Correct 93 ms 10200 KB Output is correct
29 Partially correct 96 ms 10384 KB Output is partially correct
30 Partially correct 97 ms 10296 KB Output is partially correct
31 Correct 104 ms 10232 KB Output is correct
32 Correct 111 ms 10168 KB Output is correct
33 Correct 107 ms 10396 KB Output is correct
34 Correct 89 ms 10224 KB Output is correct
35 Partially correct 101 ms 10252 KB Output is partially correct
36 Correct 90 ms 10152 KB Output is correct
37 Partially correct 115 ms 10360 KB Output is partially correct
38 Correct 94 ms 10284 KB Output is correct
39 Partially correct 146 ms 11400 KB Output is partially correct
40 Partially correct 143 ms 11136 KB Output is partially correct
41 Partially correct 136 ms 11128 KB Output is partially correct
42 Partially correct 141 ms 11156 KB Output is partially correct