답안 #116494

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
116494 2019-06-12T15:42:20 Z tinjyu 통행료 (IOI18_highway) C++14
5 / 100
256 ms 12612 KB
#include "highway.h"
#include <iostream>
using namespace std;

unsigned long long int tree[90005][2],t[100005][2],father[90005][2],cnt,road[90005],map[260005][2],m,p[130005];
long long int check()
{
	vector<int> w(m);
	for(int i=0;i<m;i++)w[i]=p[i];
	for(int i=0;i<m;i++)p[i]=1;
	return ask(w);
}
void find_pair(int n,vector<int> u,vector<int> v,int a, int b) {
	m=u.size();
	for(int i=0;i<n;i++)road[i]=-1;
	for(int i=0;i<m;i++)
	{
		int x=u[i],y=v[i];
		map[i*2][0]=x;
		map[i*2][1]=road[y];
		road[y]=i*2;
		map[i*2+1][0]=y;
		map[i*2+1][1]=road[x];
		road[x]=i*2+1;
	}
	for(int i=0;i<m;i++)p[i]=1;
	cnt=check();
	//cout<<cnt<<endl;
	int point;
	int l=0,r=m-1;
	while(l<=r)
	{
		int mid=(l+r)/2;
		for(int i=l;i<=mid;i++)p[i]=0;
		int tmp=check();
		if(tmp<cnt)
		{
			r=mid-1;
			point=mid;
		}
		else l=mid+1;
	}
	long long int start=u[point];
	long long int end=v[point];
	int tp=1,tpp=2;
	t[1][0]=start;
	t[1][1]=0;
	t[2][0]=end;
	t[2][1]=1;
	tree[0][0]++;
	tree[0][1]++;
	tree[1][0]=start;
	tree[1][1]=end;
	for(int i=0;i<n;i++)father[i][0]=-2;
	father[start][0]=-1;
	father[start][1]=130000;
	father[end][0]=-1;
	father[end][1]=130000;
	while(tp<=tpp)
	{
		int now=t[tp][0];
		int g=road[now];
		while(g!=-1)
		{
			if(father[map[g][0]][0]==-2)
			{
				father[map[g][0]][0]=now;
				father[map[g][0]][1]=g/2;
				tpp++;
				t[tpp][0]=map[g][0];
				t[tpp][1]=t[tp][1];
				tree[0][t[tp][1]]++;
				tree[tree[0][t[tp][1]]][t[tp][1]]=map[g][0];
			}
			g=map[g][1];
		}
		tp++;
	}
	for(int i=1;i<=tree[0][0];i++)
	{
		int g=tree[i][0];
		//cout<<tree[i][0]<<" "; 
		while(p[father[g][1]]==1)
		{
			p[father[g][1]]=0;
			g=father[g][0];
		}
	}
	//cout<<endl;
	cnt=check();
	l=1,r=tree[0][0];
	int startans;
	while(l<=r)
	{
		int mid=(l+r)/2;
		for(int i=l;i<=mid;i++)
		{
			int g=tree[i][0];
			while(p[father[g][1]]==1)
			{
				p[father[g][1]]=0;
				g=father[g][0];
			}
		}
		int tmp=check();
		if(tmp==cnt)
		{
			startans=tree[mid][0];
			r=mid-1;
		}
		else l=mid+1;
	}
	for(int i=1;i<=tree[0][1];i++)
	{
		int g=tree[i][1];
		while(p[father[g][1]]==1)
		{
			p[father[g][1]]=0;
			g=father[g][0];
		}
	}
	//cout<<endl;
	cnt=check();
	//cout<<cnt<<endl;
	l=1,r=tree[0][1];
	int endans;
	while(l<=r)
	{
		int mid=(l+r)/2;
		//cout<<l<<" "<<r<<endl;
		for(int i=l;i<=mid;i++)
		{
			int g=tree[i][1];
			while(p[father[g][1]]==1)
			{
				//cout<<father[g][1]<<" ";
				p[father[g][1]]=0;
				g=father[g][0];
			}
		}
		//cout<<endl;
		int tmp=check();
		//cout<<tmp<<endl;
		if(tmp==cnt)
		{
			endans=tree[mid][1];
			r=mid-1;
		}
		else l=mid+1;
	}
	//cout<<startans<<" "<<endans<<endl;
	answer(startans,endans);
}

Compilation message

highway.cpp: In function 'long long int check()':
highway.cpp:9:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<m;i++)w[i]=p[i];
              ~^~
highway.cpp:10:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<m;i++)p[i]=1;
              ~^~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:16:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<m;i++)
              ~^~
highway.cpp:26:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<m;i++)p[i]=1;
              ~^~
highway.cpp:36:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(tmp<cnt)
      ~~~^~~~
highway.cpp:65:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(father[map[g][0]][0]==-2)
       ~~~~~~~~~~~~~~~~~~~~^~~~
highway.cpp:79:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1;i<=tree[0][0];i++)
              ~^~~~~~~~~~~~
highway.cpp:106:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(tmp==cnt)
      ~~~^~~~~
highway.cpp:113:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1;i<=tree[0][1];i++)
              ~^~~~~~~~~~~~
highway.cpp:144:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(tmp==cnt)
      ~~~^~~~~
highway.cpp:152:8: warning: 'endans' may be used uninitialized in this function [-Wmaybe-uninitialized]
  answer(startans,endans);
  ~~~~~~^~~~~~~~~~~~~~~~~
highway.cpp:152:8: warning: 'startans' may be used uninitialized in this function [-Wmaybe-uninitialized]
highway.cpp:43:29: warning: 'point' may be used uninitialized in this function [-Wmaybe-uninitialized]
  long long int start=u[point];
                             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 352 KB Output is correct
2 Correct 2 ms 436 KB Output is correct
3 Correct 2 ms 428 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 376 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 344 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 452 KB Output is correct
2 Correct 16 ms 1392 KB Output is correct
3 Correct 180 ms 10584 KB Output is correct
4 Correct 217 ms 10676 KB Output is correct
5 Correct 188 ms 10688 KB Output is correct
6 Correct 169 ms 10564 KB Output is correct
7 Correct 158 ms 10724 KB Output is correct
8 Correct 207 ms 10580 KB Output is correct
9 Correct 182 ms 10572 KB Output is correct
10 Correct 192 ms 10572 KB Output is correct
11 Correct 205 ms 9992 KB Output is correct
12 Correct 208 ms 10380 KB Output is correct
13 Correct 202 ms 10728 KB Output is correct
14 Incorrect 256 ms 10480 KB Output is incorrect: {s, t} is wrong.
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 1448 KB Output is correct
2 Correct 36 ms 2560 KB Output is correct
3 Correct 42 ms 3704 KB Output is correct
4 Correct 176 ms 10140 KB Output is correct
5 Correct 181 ms 10052 KB Output is correct
6 Correct 176 ms 10384 KB Output is correct
7 Correct 134 ms 10564 KB Output is correct
8 Correct 182 ms 10152 KB Output is correct
9 Incorrect 171 ms 10560 KB Output is incorrect: {s, t} is wrong.
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 424 KB Output is correct
2 Correct 38 ms 1292 KB Output is correct
3 Correct 139 ms 8388 KB Output is correct
4 Correct 205 ms 10632 KB Output is correct
5 Correct 181 ms 10564 KB Output is correct
6 Correct 170 ms 10608 KB Output is correct
7 Correct 174 ms 10580 KB Output is correct
8 Correct 151 ms 10576 KB Output is correct
9 Runtime error 150 ms 12612 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 1472 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 1400 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -