답안 #556147

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
556147 2022-05-02T13:39:39 Z jamezzz 통행료 (IOI18_highway) C++17
100 / 100
201 ms 13024 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
#define pf printf
#define pb push_back
#define all(x) x.begin(),x.end()

#define maxn 90005

int n,m,a,b,dist[maxn][2],pedge[maxn][2],s[maxn];
ll d;
vi ord[2];
vector<ii> AL[maxn];

void find_pair(int _n,vi u,vi v,int _a,int _b){
	n=_n;a=_a;b=_b;
	m=u.size();
	
	for(int i=0;i<m;++i){
		AL[u[i]].pb({v[i],i});
		AL[v[i]].pb({u[i],i});
	}
	
	vi w(m);
	d=ask(w)/a;
	
	vi pos;
	int lo=0,hi=m-1,mid,res;
	while(lo<=hi){
		mid=(lo+hi)>>1;
		vi w(m);
		for(int i=0;i<=mid;++i)w[i]=1;
		if(ask(w)>d*a)res=mid,hi=mid-1;
		else lo=mid+1;
	}
	int f=res;
	vi r={u[f],v[f]};
	
	memset(dist,-1,sizeof dist);
	for(int i=0;i<2;++i){
		queue<int> q;
		dist[r[i]][i]=0;
		q.push(r[i]);
		while(!q.empty()){
			int u=q.front();q.pop();
			ord[i].pb(u);
			for(auto[v,x]:AL[u]){
				if(dist[v][i]!=-1)continue;
				dist[v][i]=dist[u][i]+1;
				pedge[v][i]=x;
				q.push(v);
			}
		}
	}
	for(int i=0;i<n;++i){
		if(dist[i][1]<dist[i][0])s[i]=1;
	}
	vi ans={0,0};
	for(int x=0;x<2;++x){
		vi pos;
		int idk=pedge[4410][0];//test
		int cnt=0;
		for(int i:ord[x]){
			if(i!=r[x]&&s[i]==x){
				pos.pb(pedge[i][x]);
			}
		}
		vi w(m);
		for(int i=0;i<m;++i){
			if(i!=f&&(s[u[i]]==x||s[v[i]]==x))w[i]=1;
		}
		for(int i:pos)w[i]=0;
		int lo=-1,hi=pos.size()-1,mid,res=-1;
		while(lo<=hi){
			int mid=((lo+hi+2)>>1)-1;
			for(int i=mid+1;i<pos.size();++i)w[pos[i]]=1;
			if(ask(w)==d*a)res=mid,hi=mid-1;
			else lo=mid+1;
			for(int i=mid+1;i<pos.size();++i)w[pos[i]]=0;
		}
		if(res==-1)ans[x]=r[x];
		else{
			int e=pos[res];
			ans[x]=(dist[u[e]][x]>dist[v[e]][x])?u[e]:v[e];
		}
	}
	answer(ans[0],ans[1]);
}

Compilation message

highway.cpp: In function 'void find_pair(int, vi, vi, int, int)':
highway.cpp:80:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |    for(int i=mid+1;i<pos.size();++i)w[pos[i]]=1;
      |                    ~^~~~~~~~~~~
highway.cpp:83:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |    for(int i=mid+1;i<pos.size();++i)w[pos[i]]=0;
      |                    ~^~~~~~~~~~~
highway.cpp:65:7: warning: unused variable 'idk' [-Wunused-variable]
   65 |   int idk=pedge[4410][0];//test
      |       ^~~
highway.cpp:66:7: warning: unused variable 'cnt' [-Wunused-variable]
   66 |   int cnt=0;
      |       ^~~
highway.cpp:77:29: warning: unused variable 'mid' [-Wunused-variable]
   77 |   int lo=-1,hi=pos.size()-1,mid,res=-1;
      |                             ^~~
highway.cpp:41:11: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   41 |  vi r={u[f],v[f]};
      |           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3024 KB Output is correct
2 Correct 2 ms 3024 KB Output is correct
3 Correct 2 ms 3024 KB Output is correct
4 Correct 3 ms 3024 KB Output is correct
5 Correct 2 ms 3024 KB Output is correct
6 Correct 3 ms 3024 KB Output is correct
7 Correct 2 ms 3024 KB Output is correct
8 Correct 2 ms 3024 KB Output is correct
9 Correct 2 ms 3024 KB Output is correct
10 Correct 2 ms 3024 KB Output is correct
11 Correct 2 ms 3024 KB Output is correct
12 Correct 2 ms 3024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3152 KB Output is correct
2 Correct 13 ms 4048 KB Output is correct
3 Correct 121 ms 10776 KB Output is correct
4 Correct 103 ms 11032 KB Output is correct
5 Correct 113 ms 10900 KB Output is correct
6 Correct 111 ms 10912 KB Output is correct
7 Correct 117 ms 10900 KB Output is correct
8 Correct 117 ms 10908 KB Output is correct
9 Correct 112 ms 10708 KB Output is correct
10 Correct 112 ms 10984 KB Output is correct
11 Correct 175 ms 10412 KB Output is correct
12 Correct 120 ms 10260 KB Output is correct
13 Correct 127 ms 10404 KB Output is correct
14 Correct 118 ms 10300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 3980 KB Output is correct
2 Correct 20 ms 4724 KB Output is correct
3 Correct 32 ms 5468 KB Output is correct
4 Correct 92 ms 10192 KB Output is correct
5 Correct 90 ms 10196 KB Output is correct
6 Correct 87 ms 10244 KB Output is correct
7 Correct 91 ms 9988 KB Output is correct
8 Correct 89 ms 10292 KB Output is correct
9 Correct 88 ms 9984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3152 KB Output is correct
2 Correct 13 ms 4024 KB Output is correct
3 Correct 81 ms 9208 KB Output is correct
4 Correct 147 ms 10992 KB Output is correct
5 Correct 108 ms 10680 KB Output is correct
6 Correct 138 ms 10988 KB Output is correct
7 Correct 125 ms 10604 KB Output is correct
8 Correct 133 ms 10572 KB Output is correct
9 Correct 123 ms 10908 KB Output is correct
10 Correct 118 ms 10940 KB Output is correct
11 Correct 126 ms 10328 KB Output is correct
12 Correct 115 ms 10396 KB Output is correct
13 Correct 131 ms 10264 KB Output is correct
14 Correct 124 ms 10348 KB Output is correct
15 Correct 114 ms 10976 KB Output is correct
16 Correct 136 ms 10908 KB Output is correct
17 Correct 118 ms 10376 KB Output is correct
18 Correct 116 ms 10432 KB Output is correct
19 Correct 107 ms 10576 KB Output is correct
20 Correct 126 ms 10300 KB Output is correct
21 Correct 102 ms 11416 KB Output is correct
22 Correct 100 ms 11292 KB Output is correct
23 Correct 110 ms 11084 KB Output is correct
24 Correct 99 ms 11068 KB Output is correct
25 Correct 112 ms 10568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 4020 KB Output is correct
2 Correct 15 ms 4092 KB Output is correct
3 Correct 123 ms 11348 KB Output is correct
4 Correct 143 ms 11660 KB Output is correct
5 Correct 172 ms 12880 KB Output is correct
6 Correct 184 ms 12856 KB Output is correct
7 Correct 183 ms 12904 KB Output is correct
8 Correct 182 ms 12804 KB Output is correct
9 Correct 121 ms 10208 KB Output is correct
10 Correct 122 ms 10488 KB Output is correct
11 Correct 139 ms 11088 KB Output is correct
12 Correct 160 ms 12260 KB Output is correct
13 Correct 181 ms 12552 KB Output is correct
14 Correct 174 ms 12932 KB Output is correct
15 Correct 186 ms 12652 KB Output is correct
16 Correct 156 ms 11216 KB Output is correct
17 Correct 125 ms 11120 KB Output is correct
18 Correct 104 ms 11304 KB Output is correct
19 Correct 110 ms 11284 KB Output is correct
20 Correct 114 ms 11312 KB Output is correct
21 Correct 160 ms 12836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 4052 KB Output is correct
2 Correct 18 ms 4100 KB Output is correct
3 Correct 136 ms 11492 KB Output is correct
4 Correct 140 ms 11532 KB Output is correct
5 Correct 158 ms 11876 KB Output is correct
6 Correct 172 ms 12800 KB Output is correct
7 Correct 117 ms 11308 KB Output is correct
8 Correct 140 ms 11504 KB Output is correct
9 Correct 159 ms 11828 KB Output is correct
10 Correct 173 ms 12820 KB Output is correct
11 Correct 173 ms 12920 KB Output is correct
12 Correct 167 ms 12812 KB Output is correct
13 Correct 128 ms 11244 KB Output is correct
14 Correct 125 ms 10404 KB Output is correct
15 Correct 134 ms 11140 KB Output is correct
16 Correct 118 ms 10416 KB Output is correct
17 Correct 132 ms 11124 KB Output is correct
18 Correct 121 ms 10616 KB Output is correct
19 Correct 166 ms 12300 KB Output is correct
20 Correct 165 ms 12596 KB Output is correct
21 Correct 170 ms 12860 KB Output is correct
22 Correct 184 ms 12836 KB Output is correct
23 Correct 201 ms 12820 KB Output is correct
24 Correct 175 ms 12848 KB Output is correct
25 Correct 188 ms 12632 KB Output is correct
26 Correct 170 ms 12652 KB Output is correct
27 Correct 103 ms 11356 KB Output is correct
28 Correct 100 ms 11152 KB Output is correct
29 Correct 100 ms 11168 KB Output is correct
30 Correct 101 ms 10936 KB Output is correct
31 Correct 104 ms 11200 KB Output is correct
32 Correct 118 ms 11128 KB Output is correct
33 Correct 102 ms 11364 KB Output is correct
34 Correct 111 ms 11220 KB Output is correct
35 Correct 106 ms 11268 KB Output is correct
36 Correct 113 ms 11096 KB Output is correct
37 Correct 109 ms 11384 KB Output is correct
38 Correct 98 ms 11300 KB Output is correct
39 Correct 169 ms 13024 KB Output is correct
40 Correct 157 ms 12660 KB Output is correct
41 Correct 173 ms 12696 KB Output is correct
42 Correct 175 ms 12888 KB Output is correct