답안 #114919

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
114919 2019-06-03T23:18:02 Z tutis 통행료 (IOI18_highway) C++17
40 / 100
244 ms 10564 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);
		}
	}
	fill_n(w.begin(), M, 1);
	if (v[0].size() > 1)
		for (int i : v[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);
		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:135: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:96:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < s.size(); i++)
                   ~~^~~~~~~~~~
highway.cpp:98:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (i < s.size() / 2)
        ~~^~~~~~~~~~~~~~
highway.cpp:114:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < t.size(); i++)
                   ~~^~~~~~~~~~
highway.cpp:116:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (i < t.size() / 2)
        ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 296 KB Output is correct
2 Correct 2 ms 248 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 404 KB Output is correct
5 Correct 2 ms 248 KB Output is correct
6 Incorrect 2 ms 248 KB Output is incorrect: {s, t} is wrong.
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 388 KB Output is correct
2 Correct 23 ms 1380 KB Output is correct
3 Correct 196 ms 9584 KB Output is correct
4 Correct 231 ms 9592 KB Output is correct
5 Correct 210 ms 9624 KB Output is correct
6 Correct 193 ms 9628 KB Output is correct
7 Correct 206 ms 9580 KB Output is correct
8 Correct 200 ms 9592 KB Output is correct
9 Correct 186 ms 9580 KB Output is correct
10 Correct 194 ms 9588 KB Output is correct
11 Correct 174 ms 9420 KB Output is correct
12 Correct 182 ms 9488 KB Output is correct
13 Correct 192 ms 9496 KB Output is correct
14 Correct 207 ms 9544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 1320 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 38 ms 1324 KB Output is correct
3 Correct 141 ms 7716 KB Output is correct
4 Correct 200 ms 9588 KB Output is correct
5 Correct 199 ms 9548 KB Output is correct
6 Correct 189 ms 9640 KB Output is correct
7 Correct 158 ms 9608 KB Output is correct
8 Correct 175 ms 9580 KB Output is correct
9 Correct 229 ms 9576 KB Output is correct
10 Correct 214 ms 9608 KB Output is correct
11 Correct 218 ms 9528 KB Output is correct
12 Correct 214 ms 9616 KB Output is correct
13 Correct 203 ms 9492 KB Output is correct
14 Correct 236 ms 9280 KB Output is correct
15 Correct 178 ms 9536 KB Output is correct
16 Correct 219 ms 9648 KB Output is correct
17 Correct 201 ms 9492 KB Output is correct
18 Correct 187 ms 9500 KB Output is correct
19 Correct 213 ms 9588 KB Output is correct
20 Correct 189 ms 9492 KB Output is correct
21 Correct 185 ms 10564 KB Output is correct
22 Correct 175 ms 10496 KB Output is correct
23 Correct 182 ms 10208 KB Output is correct
24 Correct 201 ms 10132 KB Output is correct
25 Correct 244 ms 9544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 1404 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 1384 KB Output is correct
2 Correct 24 ms 1436 KB Output is correct
3 Correct 221 ms 9936 KB Output is correct
4 Correct 230 ms 10012 KB Output is correct
5 Incorrect 232 ms 10388 KB Output is incorrect: {s, t} is wrong.
6 Halted 0 ms 0 KB -