Submission #99350

# Submission time Handle Problem Language Result Execution time Memory
99350 2019-03-02T21:03:04 Z TadijaSebez Highway Tolls (IOI18_highway) C++11
0 / 100
26 ms 6128 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)
			{
				if(f[y]==f[x]) I[y].pb(id);
				else 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:56:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    mid=top+bot>>1;
        ~~~^~~~
highway.cpp:59: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 6 ms 4984 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 5856 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 5044 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 6128 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 6004 KB Incorrect
2 Halted 0 ms 0 KB -