Submission #123244

# Submission time Handle Problem Language Result Execution time Memory
123244 2019-06-30T16:17:23 Z imyujin Highway Tolls (IOI18_highway) C++14
0 / 100
46 ms 3308 KB
#include "highway.h"
#include<vector>
#include<queue>
#include<bitset>

using namespace std;

#define MAXN 90005

typedef pair<int, int> pii;

int N, M, A, B;
int d, se;
vector<pii> ed[MAXN];
int da[MAXN], db[MAXN];
bitset<MAXN> chk;
int num[MAXN];

void bfs(int x, int dx[]) {
	queue<int> q;

	for(int i = 0; i < N; i++) dx[i] = -1;
	dx[x] = 0;
	q.push(x);
	while(!q.empty()) {
		int t = q.front();
		q.pop();
		for(auto a : ed[t]) if(dx[a.first] == -1) {
			dx[a.first] = dx[t] + 1;
			q.push(a.first);
		}
	}
}

int f(int x, int dx[], int dy[]) {
	queue<int> q;
	vector<int> con;

	for(int i = 0; i < N; i++) chk[i] = false;
	q.push(x);
	chk[x] = true;
	while(!q.empty()) {
		int t = q.front();
		q.pop();
		con.push_back(t);
		for(auto a : ed[t]) if(dx[a.first] < dy[a.first] && !chk[a.first]) {
			chk[a.first] = true;
			q.push(a.first);
		}
	}

	for(int i = 0; i < N; i++) num[i] = -1;
	for(int i = 0; i < con.size(); i++) num[con[i]] = i;

	/*
	for(auto a : con) printf("%d ", a);
	printf("\n");
	*/

	vector<int> w(M, 0);
	int s = 0, e = con.size() - 1;
	int m = s + e >> 1;
	for(int i = m + 1; i <= e; i++) for(auto a : ed[con[i]]) w[a.second] = 1;
	while(s < e) {
		//printf("s = %d, e = %d\n", s, e);
		if(ask(w) == d * A) {
			e = m;
			m = s + e >> 1;
			for(int i = m + 1; i <= e; i++) for(auto a : ed[con[i]]) w[a.second] = 1;
		}
		else {
			s = m + 1;
			m = s + e >> 1;
			for(int i = s + 1; i <= m; i++) for(auto a : ed[con[i]]) if(num[a.first] < i) w[a.second] = 0;
		}
	}
	return con[s];
}

void find_pair(int n, vector<int> U, vector<int> V, int a, int b) {
	N = n;
	M = U.size();
	A = a;
	B = b;
	vector<int> w(M, 0);

	for(int i = 0; i < M; i++) {
		ed[U[i]].push_back(make_pair(V[i], i));
		ed[V[i]].push_back(make_pair(U[i], i));
	}

	d = ask(w) / A;
	int s = 0, e = M - 1, m = N - 1 >> 1;
	for(int i = m + 1; i <= e; i++) w[i] = 1;
	while(s < e) {
		if(ask(w) != A * d) {
			s = m + 1;
			m = s + e >> 1;
			for(int i = s; i <= m; i++) w[i] = 0;
		}
		else {
			e = m;
			m = s + e >> 1;
			for(int i = m + 1; i <= e; i++) w[i] = 1;
		}
	}
	se = s;


	int alpha = U[se], beta = V[se];
	//printf("se=%d(%d, %d)\n", se, alpha, beta);
	bfs(alpha, da);
	bfs(beta, db);
	//for(int i = 0; i < N; i++) printf("[%d %d]\n", da[i], db[i]);
	answer(f(alpha, da, db), f(beta, db, da));
}

Compilation message

highway.cpp: In function 'int f(int, int*, int*)':
highway.cpp:53:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < con.size(); i++) num[con[i]] = i;
                 ~~^~~~~~~~~~~~
highway.cpp:62:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int m = s + e >> 1;
          ~~^~~
highway.cpp:68:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    m = s + e >> 1;
        ~~^~~
highway.cpp:73:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    m = s + e >> 1;
        ~~^~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:93:30: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
  int s = 0, e = M - 1, m = N - 1 >> 1;
                            ~~^~~
highway.cpp:98:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    m = s + e >> 1;
        ~~^~~
highway.cpp:103:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    m = s + e >> 1;
        ~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2512 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2552 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 3268 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2560 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 3228 KB Output is correct
2 Incorrect 30 ms 3308 KB Output is incorrect: {s, t} is wrong.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 3244 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -