답안 #114922

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
114922 2019-06-03T23:42:33 Z tutis 통행료 (IOI18_highway) C++17
51 / 100
271 ms 10572 KB
#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
typedef long long ll;
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B)
{
	vector<int>adj[N];
	int M = U.size();
	for (int i = 0; i < M; i++)
	{
		adj[U[i]].push_back(V[i]);
		adj[V[i]].push_back(U[i]);
	}
	vector<int>tarp;
	for (int i = 0; i < M; i++)
		tarp.push_back(i);
	vector<int>w(M, 1);
	ll maxi = ask(w);
	while (tarp.size() > 1)
	{
		vector<int>t1;
		vector<int>t2;
		for (int i = 0; i < tarp.size(); i++)
		{
			if (i < tarp.size() / 2)
				t1.push_back(tarp[i]);
			else
				t2.push_back(tarp[i]);
		}
		fill_n(w.begin(), M, 1);
		for (int i : t1)
			w[i] = 0;
		if (ask(w) < maxi)
			tarp = t1;
		else
			tarp = t2;
	}
	assert(tarp.size() == 1);
	int u[2] = {U[tarp[0]], V[tarp[0]]};
	int d[2][N];
	int pa[2][N];
	for (int t : {0, 1})
	{
		fill_n(d[t], N, N + 3);
		d[t][u[t]] = 0;
		queue<int>Q;
		Q.push(u[t]);
		while (!Q.empty())
		{
			int a = Q.front();
			Q.pop();
			for (int b : adj[a])
			{
				if (d[t][b] > d[t][a] + 1)
				{
					d[t][b] = d[t][a] + 1;
					Q.push(b);
				}
			}
		}
		for (int i = 0; i < M; i++)
		{
			if (d[t][U[i]] < d[t][V[i]])
				pa[t][V[i]] = i;
			if (d[t][U[i]] > d[t][V[i]])
				pa[t][U[i]] = i;
		}
	}
	ll d_st = maxi / ll(B);
	vector<int>v[2];
	for (int t : {0, 1})
	{
		for (int i = 0; i < N; i++)
		{
			if (d[t][i] < d[1 - t][i])
				v[t].push_back(i);
		}
	}
	fill_n(w.begin(), M, 1);
	for (int i : v[0])
	{
		if (i != u[0])
			w[pa[0][i]] = 0;
	}
	int d_s = ((maxi - ask(w)) / ll(B - A));
	int d_t = d_st - d_s - 1;
	vector<int>s, t;
	for (int i : v[0])
		if (d[0][i] == d_s)
			s.push_back(i);
	for (int i : v[1])
		if (d[1][i] == d_t)
			t.push_back(i);
	while (s.size() > 1)
	{
		vector<int>s1, s2;
		for (int i = 0; i < s.size(); i++)
		{
			if (i < s.size() / 2)
				s1.push_back(s[i]);
			else
				s2.push_back(s[i]);
		}
		fill_n(w.begin(), M, 1ll);
		w[tarp[0]] = 0;
		for (int i : s1)
			w[pa[0][i]] = 0;
		if (ask(w) < maxi - (B - A))
			s = s1;
		else
			s = s2;
	}
	while (t.size() > 1)
	{
		vector<int>t1, t2;
		for (int i = 0; i < t.size(); i++)
		{
			if (i < t.size() / 2)
				t1.push_back(t[i]);
			else
				t2.push_back(t[i]);
		}
		fill_n(w.begin(), M, 1ll);
		w[tarp[0]] = 0;
		for (int i : t1)
			w[pa[1][i]] = 0;
		if (ask(w) < maxi - (B - A))
			t = t1;
		else
			t = t2;
	}
	answer(s[0], t[0]);
}/*
int main()
{

}
/**/

Compilation message

highway.cpp:138:1: warning: "/*" within comment [-Wcomment]
 /**/
  
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:23:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < tarp.size(); i++)
                   ~~^~~~~~~~~~~~~
highway.cpp:25:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (i < tarp.size() / 2)
        ~~^~~~~~~~~~~~~~~~~
highway.cpp:97:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < s.size(); i++)
                   ~~^~~~~~~~~~
highway.cpp:99:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (i < s.size() / 2)
        ~~^~~~~~~~~~~~~~
highway.cpp:116:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < t.size(); i++)
                   ~~^~~~~~~~~~
highway.cpp:118:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (i < t.size() / 2)
        ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 420 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 248 KB Output is correct
4 Correct 2 ms 404 KB Output is correct
5 Correct 2 ms 320 KB Output is correct
6 Correct 2 ms 308 KB Output is correct
7 Correct 2 ms 248 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 248 KB Output is correct
10 Correct 2 ms 320 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 396 KB Output is correct
2 Correct 29 ms 1380 KB Output is correct
3 Correct 195 ms 9584 KB Output is correct
4 Correct 205 ms 9644 KB Output is correct
5 Correct 196 ms 9620 KB Output is correct
6 Correct 195 ms 9588 KB Output is correct
7 Correct 192 ms 9588 KB Output is correct
8 Correct 216 ms 9588 KB Output is correct
9 Correct 204 ms 9580 KB Output is correct
10 Correct 191 ms 9592 KB Output is correct
11 Correct 180 ms 9416 KB Output is correct
12 Correct 182 ms 9488 KB Output is correct
13 Correct 211 ms 9484 KB Output is correct
14 Correct 198 ms 9488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 1376 KB Output is correct
2 Correct 38 ms 2300 KB Output is correct
3 Correct 42 ms 3328 KB Output is correct
4 Correct 157 ms 9412 KB Output is correct
5 Correct 155 ms 9364 KB Output is correct
6 Correct 161 ms 9624 KB Output is correct
7 Correct 153 ms 9548 KB Output is correct
8 Correct 155 ms 9368 KB Output is correct
9 Correct 137 ms 9520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 472 KB Output is correct
2 Correct 22 ms 1332 KB Output is correct
3 Correct 154 ms 7660 KB Output is correct
4 Correct 202 ms 9588 KB Output is correct
5 Correct 206 ms 9652 KB Output is correct
6 Correct 186 ms 9588 KB Output is correct
7 Correct 198 ms 9664 KB Output is correct
8 Correct 193 ms 9576 KB Output is correct
9 Correct 206 ms 9592 KB Output is correct
10 Correct 200 ms 9592 KB Output is correct
11 Correct 203 ms 9476 KB Output is correct
12 Correct 199 ms 9620 KB Output is correct
13 Correct 224 ms 9544 KB Output is correct
14 Correct 217 ms 9224 KB Output is correct
15 Correct 179 ms 9564 KB Output is correct
16 Correct 192 ms 9588 KB Output is correct
17 Correct 208 ms 9488 KB Output is correct
18 Correct 218 ms 9460 KB Output is correct
19 Correct 198 ms 9644 KB Output is correct
20 Correct 202 ms 9480 KB Output is correct
21 Correct 214 ms 10572 KB Output is correct
22 Correct 168 ms 10384 KB Output is correct
23 Correct 184 ms 10224 KB Output is correct
24 Correct 184 ms 10144 KB Output is correct
25 Correct 203 ms 9512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 1424 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 1372 KB Output is correct
2 Correct 25 ms 1388 KB Output is correct
3 Correct 235 ms 9736 KB Output is correct
4 Correct 232 ms 10000 KB Output is correct
5 Correct 247 ms 10152 KB Output is correct
6 Incorrect 271 ms 10440 KB Output is incorrect: {s, t} is wrong.
7 Halted 0 ms 0 KB -