답안 #114918

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
114918 2019-06-03T23:12:06 Z tutis 통행료 (IOI18_highway) C++17
18 / 100
243 ms 10476 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;
		}
		pa[t][u[t]] = u[t];
	}
	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);
		}
	}
	int lo = 0;
	int hi = N;
	while (lo < hi)
	{
		fill_n(w.begin(), M, 1ll);
		int d_s = (lo + hi) / 2;
		for (int i : v[0])
			if (d[0][i] > d_s)
				w[pa[0][i]] = 0;
		if (ask(w) == maxi)
			hi = d_s;
		else
			lo = d_s + 1;
	}
	int d_s = (lo + hi) / 2;
	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);
		for (int i : s1)
			w[pa[0][i]] = 0;
		if (ask(w) < maxi)
			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);
		for (int i : t1)
			w[pa[1][i]] = 0;
		if (ask(w) < maxi)
			t = t1;
		else
			t = t2;
	}
	answer(s[0], t[0]);
}/*
int main()
{

}
/**/

Compilation message

highway.cpp:145: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:106:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < s.size(); i++)
                   ~~^~~~~~~~~~
highway.cpp:108:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (i < s.size() / 2)
        ~~^~~~~~~~~~~~~~
highway.cpp:124:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < t.size(); i++)
                   ~~^~~~~~~~~~
highway.cpp:126:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (i < t.size() / 2)
        ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 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 376 KB Output is correct
5 Correct 2 ms 248 KB Output is correct
6 Correct 2 ms 248 KB Output is correct
7 Correct 2 ms 400 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 320 KB Output is correct
11 Correct 2 ms 248 KB Output is correct
12 Correct 2 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 23 ms 1324 KB Output is correct
3 Correct 218 ms 9596 KB Output is correct
4 Correct 195 ms 9668 KB Output is correct
5 Correct 236 ms 9552 KB Output is correct
6 Correct 200 ms 9532 KB Output is correct
7 Correct 221 ms 9596 KB Output is correct
8 Correct 199 ms 9584 KB Output is correct
9 Correct 199 ms 9588 KB Output is correct
10 Correct 234 ms 9584 KB Output is correct
11 Correct 202 ms 9504 KB Output is correct
12 Correct 226 ms 9528 KB Output is correct
13 Correct 200 ms 9460 KB Output is correct
14 Correct 212 ms 9508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 1272 KB Output is correct
2 Correct 32 ms 2316 KB Output is correct
3 Correct 53 ms 3368 KB Output is correct
4 Correct 175 ms 9448 KB Output is correct
5 Correct 177 ms 9420 KB Output is correct
6 Correct 164 ms 9712 KB Output is correct
7 Correct 153 ms 9488 KB Output is correct
8 Correct 193 ms 9412 KB Output is correct
9 Correct 171 ms 9488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 392 KB Output is correct
2 Correct 24 ms 1324 KB Output is correct
3 Correct 151 ms 7716 KB Output is correct
4 Correct 192 ms 9604 KB Output is correct
5 Correct 200 ms 9584 KB Output is correct
6 Correct 196 ms 9656 KB Output is correct
7 Correct 197 ms 9580 KB Output is correct
8 Correct 230 ms 9580 KB Output is correct
9 Correct 243 ms 9568 KB Output is correct
10 Correct 204 ms 9616 KB Output is correct
11 Correct 227 ms 9452 KB Output is correct
12 Correct 233 ms 9616 KB Output is correct
13 Correct 218 ms 9484 KB Output is correct
14 Correct 212 ms 9284 KB Output is correct
15 Correct 173 ms 9572 KB Output is correct
16 Correct 194 ms 9584 KB Output is correct
17 Correct 204 ms 9484 KB Output is correct
18 Correct 194 ms 9456 KB Output is correct
19 Correct 176 ms 9560 KB Output is correct
20 Correct 214 ms 9536 KB Output is correct
21 Correct 179 ms 10384 KB Output is correct
22 Correct 194 ms 10476 KB Output is correct
23 Incorrect 234 ms 10224 KB Output isn't correct
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 1408 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 1340 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -