Submission #72746

# Submission time Handle Problem Language Result Execution time Memory
72746 2018-08-26T22:07:34 Z Pajaraja Jakarta Skyscrapers (APIO15_skyscraper) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define MAXN 30007
using namespace std;
vector<int> g[MAXN],w[MAXN],a[MAXN];
set<int> v[MAXN];
bool vi[MAXN];
int dist[MAXN],en;
void dijkstra(int s)
{
	priority_queue<pair<int,int> > pq;
	pq.push(make_pair(0,s));
	while(!pq.empty())
	{
		int u=pq.top().second,d=-pq.top().first;
		pq.pop();
		if(vi[u]) continue;
		dist[u]=d;
		vi[u]=true;
		if(u==en) return;
		for(int i=0;i<g[u].size();i++) if(!vi[g[u][i]]) pq.push(make_pair(-d-w[u][i],g[u][i]));
	}
}
/*bool binarna(int l,int r,int k,int val)
{
	if(r<l) return false;
	int s=(l+r)/2;
	if(v[k][s]==val) return true;
	if(val<v[k][s]) return binarna(l,s-1,k,val);
	return binarna(s+1,r,k,val);
}*/
int main()
{
	int n,m,st,t1,t2;
	scanf("%d%d",&n,&m);
	scanf("%d%d%d%d",&st,&t1,&en,&t2);
	v[st].insert(t1);
	v[en].insert(t2);
	for(int i=0;i<m-2;i++)
	{
		scanf("%d%d",&t1,&t2);
		v[t1].insert(t2);
	}
	for(int i=0;i<n;i++)
	{
		set<int>::iterator it=v[i].end();
		do
		{
			it--;
			int t=*it,cur=i+t;
			while(cur<n)
			{
				if(!vi[cur] && v[i].size()>0)
				{
					g[i].push_back(cur);
					w[i].push_back((cur-i)/t);
					vi[cur]=true;
				}
				if(v[cur].find(t)!=v[cur].end()) break;
				cur+=t;
			} 
			cur=i-t;
			while(cur>=0)
			{
				if(!vi[cur] && vi[i].size()>0)
				{
					g[i].push_back(cur);
					w[i].push_back((i-cur)/t);
					vi[cur]=true;
				}
				if(v[cur].find(t)!=v[cur].end()) break;
				cur-=t;
			}
		}  while(it!=v[i].begin());
		for(int j=0;j<g[i].size();j++) vi[j]=false;
	}
	dijkstra(st);
	if(!vi[en]) dist[en]=-1;
	printf("%d",dist[en]);
}

Compilation message

skyscraper.cpp: In function 'void dijkstra(int)':
skyscraper.cpp:20:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<g[u].size();i++) if(!vi[g[u][i]]) pq.push(make_pair(-d-w[u][i],g[u][i]));
               ~^~~~~~~~~~~~
skyscraper.cpp: In function 'int main()':
skyscraper.cpp:64:26: error: request for member 'size' in 'vi[i]', which is of non-class type 'bool'
     if(!vi[cur] && vi[i].size()>0)
                          ^~~~
skyscraper.cpp:74:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<g[i].size();j++) vi[j]=false;
               ~^~~~~~~~~~~~
skyscraper.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d",&st,&t1,&en,&t2);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
skyscraper.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&t1,&t2);
   ~~~~~^~~~~~~~~~~~~~~~