Submission #72743

# Submission time Handle Problem Language Result Execution time Memory
72743 2018-08-26T21:59:55 Z Pajaraja Jakarta Skyscrapers (APIO15_skyscraper) C++17
0 / 100
5 ms 3976 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);
		a[t1].push_back(t2);
	}
	for(int i=0;i<n;i++) sort(a[i].begin(),a[i].end());
	for(int i=0;i<n;i++)
	{
		for(int j=a[i].size()-1;j>=0;j--)
		{
			int t=a[i][j],cur=i+t;
			while(cur<n)
			{
				g[i].push_back(cur);
				w[i].push_back((cur-i)/t);
				if(v[cur].find(t)!=v[cur].end()) break;
				cur+=t;
			} 
			cur=i-t;
			while(cur>=0)
			{
				g[i].push_back(cur);
				w[i].push_back((i-cur)/t);
				if(v[cur].find(t)!=v[cur].end()) break;
				cur-=t;
			}
		}
	}
	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: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);
   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 3832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3976 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3976 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3976 KB Output isn't correct
2 Halted 0 ms 0 KB -