Submission #99349

# Submission time Handle Problem Language Result Execution time Memory
99349 2019-03-02T20:46:42 Z TadijaSebez Highway Tolls (IOI18_highway) C++11
0 / 100
27 ms 6056 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
const int N=100050;
ll dist;
vector<pair<int,int>> E[N];
vector<int> I[N];
int d[N],f[N];
void AddEdge(int u, int v, int id){ E[u].pb(mp(v,id));E[v].pb(mp(u,id));}
void find_pair(int n, vector<int> U, vector<int> V, int A, int B)
{
    int m=U.size();
    int top=m-1,bot=0,mid,ans;
    vector<int> use(m,0);
    dist=ask(use);
    while(top>=bot)
	{
		mid=top+bot>>1;
		use.clear();use.assign(m,0);
		for(int i=0;i<=mid;i++) use[i]=1;
		if(ask(use)==dist) bot=mid+1;
		else ans=mid,top=mid-1;
	}
	for(int i=ans;i<m;i++) AddEdge(U[i],V[i],i);
	queue<int> q;q.push(U[ans]);q.push(V[ans]);
	d[U[ans]]=d[V[ans]]=1;
	f[U[ans]]=1;f[V[ans]]=2;
	vector<int> L,R;
	while(q.size())
	{
		int x=q.front();q.pop();
        if(f[x]&1) L.pb(x);
        if(f[x]&2) R.pb(x);
        for(auto e:E[x])
		{
			int y=e.first;
			int id=e.second;
			if(!d[y]) d[y]=d[x]+1,f[y]=f[x],q.push(y);
			if(d[y]==d[x]+1) I[y].pb(id),f[y]|=f[x];
		}
	}
	int bad=-1;
	auto Solve=[&](vector<int> vs)
	{
		top=(int)vs.size()-1;bot=0;
		int ret=vs[0];
		while(top>=bot)
		{
			mid=top+bot>>1;
			use.clear();use.assign(n,0);
			for(int i=0;i<ans;i++) use[i]=1;
			for(int i=mid;i<vs.size();i++) if(vs[i]!=bad) for(int id:I[vs[i]]) use[id]=1;
			if(ask(use)==dist) top=mid-1;
			else ret=vs[mid],bot=mid+1;
		}
		bad=ret;
		return ret;
	};
	return answer(Solve(L),Solve(R));
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:21:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   mid=top+bot>>1;
       ~~~^~~~
highway.cpp: In lambda function:
highway.cpp:52:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    mid=top+bot>>1;
        ~~~^~~~
highway.cpp:55:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i=mid;i<vs.size();i++) if(vs[i]!=bad) for(int id:I[vs[i]]) use[id]=1;
                  ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5112 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5112 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 6008 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5032 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 6056 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 5996 KB Incorrect
2 Halted 0 ms 0 KB -