답안 #158160

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
158160 2019-10-15T06:31:32 Z kig9981 통행료 (IOI18_highway) C++17
7 / 100
259 ms 18120 KB
#include "highway.h"
#include <bits/stdc++.h>

using namespace std;

vector<int> adj[90000];
set<int> gv[90000];
int g[90000];

void find_pair(int N, vector<int> U, vector<int> V, int A, int B)
{
	int M=U.size(), sg=0, tg=0, gnum=0;
	vector<int> W(M);
	long long dist=ask(W);
	for(int i=0;i<M;i++) {
		adj[U[i]].push_back(V[i]);
		adj[V[i]].push_back(U[i]);
	}
	for(int i=0;i<N;i++) gv[0].insert(i);
	while(gv[sg].size()>1) {
		++gnum;
		for(auto c: gv[sg]) {
			gv[gnum].insert(c);
			g[c]=gnum;
			if(2*gv[gnum].size()>=gv[sg].size()) break;
		}
		for(auto c: gv[gnum]) gv[sg].erase(c);
		if(gv[gnum].size()==1) {
			for(int i=0;i<M;i++) W[i]=g[U[i]]==gnum || g[V[i]]==gnum;
			if(ask(W)==dist+B-A) sg=gnum;
		}
		else {
			long long temp;
			for(int i=0;i<M;i++) W[i]=g[U[i]]==gnum && g[V[i]]!=gnum || g[U[i]]!=gnum && g[V[i]]==gnum;
			temp=(ask(W)-dist)/(B-A);
			if(sg==tg) {
				if(temp&1) sg=gnum;
				else if(temp) sg=tg=gnum;
			}
			else if(temp&1) sg=gnum;
		}
	}
	while(gv[tg].size()>1) {
		++gnum;
		for(auto c: gv[tg]) {
			gv[gnum].insert(c);
			g[c]=gnum;
			if(2*gv[gnum].size()>=gv[tg].size()) break;
		}
		for(auto c: gv[gnum]) gv[tg].erase(c);
		if(gv[gnum].size()==1) {
			for(int i=0;i<M;i++) W[i]=g[U[i]]==gnum || g[V[i]]==gnum;
			if(ask(W)==dist+B-A) tg=gnum;
		}
		else {
			for(int i=0;i<M;i++) W[i]=g[U[i]]==gnum && g[V[i]]!=gnum || g[U[i]]!=gnum && g[V[i]]==gnum;
			if((ask(W)-dist)/(B-A)&1) tg=gnum;
		}
	}
	answer(*gv[sg].begin(),*gv[tg].begin());
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:34:44: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
    for(int i=0;i<M;i++) W[i]=g[U[i]]==gnum && g[V[i]]!=gnum || g[U[i]]!=gnum && g[V[i]]==gnum;
                              ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
highway.cpp:56:44: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
    for(int i=0;i<M;i++) W[i]=g[U[i]]==gnum && g[V[i]]!=gnum || g[U[i]]!=gnum && g[V[i]]==gnum;
                              ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 6648 KB Output is correct
2 Correct 9 ms 6648 KB Output is correct
3 Correct 9 ms 6648 KB Output is correct
4 Correct 10 ms 6648 KB Output is correct
5 Correct 8 ms 6648 KB Output is correct
6 Correct 9 ms 6752 KB Output is correct
7 Incorrect 8 ms 6648 KB Output is incorrect: {s, t} is wrong.
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 6776 KB Output is correct
2 Correct 26 ms 7912 KB Output is correct
3 Correct 230 ms 17884 KB Output is correct
4 Correct 259 ms 17996 KB Output is correct
5 Correct 226 ms 17872 KB Output is correct
6 Correct 257 ms 17964 KB Output is correct
7 Correct 253 ms 17876 KB Output is correct
8 Correct 248 ms 17888 KB Output is correct
9 Correct 259 ms 17892 KB Output is correct
10 Correct 246 ms 17892 KB Output is correct
11 Correct 250 ms 17784 KB Output is correct
12 Correct 245 ms 17908 KB Output is correct
13 Correct 252 ms 17916 KB Output is correct
14 Correct 255 ms 17880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 7928 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6776 KB Output is correct
2 Correct 31 ms 7888 KB Output is correct
3 Incorrect 164 ms 15396 KB Output is incorrect: {s, t} is wrong.
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 7844 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 7896 KB Output is correct
2 Correct 30 ms 7952 KB Output is correct
3 Incorrect 248 ms 18120 KB Output is incorrect: {s, t} is wrong.
4 Halted 0 ms 0 KB -