답안 #72729

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
72729 2018-08-26T21:16:36 Z Pajaraja Jakarta Skyscrapers (APIO15_skyscraper) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define MAXN 30007
using namespace std;
vector<int> g[MAXN],w[MAXN],v[MAXN],c;
bool vi[MAXN];
int dist[MAXN];
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].push_back(t1);
	v[en].push_back(t2);
	for(int i=0;i<m-2;i++)
	{
		scanf("%d%d",&t1,&t2);
		v[t1].push_back(t2);
	}
	for(int i=0;i<n;i++) sort(v[i].begin(),v[i].end());
	for(int i=0;i<n;i++)
	{
		for(int j=v[i].size()-1;j>=0;j--)
		{
			int t=v[i][j],cur=i+t,cnt=0;
			while(cur<n)
			{
				cnt++;
				if(!vi[cur] && v[cur].size()>0) 
				{
					g[i].push_back(cur);
					w[i].push_back(cnt);
					vi[cur]=true;
					c.push_back(cur);
				}
				if(binarna(0,v[cur].size()-1,cur,t)) break;
				cur+=t;
			} 
			cur=i-t; cnt=0;
			while(cur>=0)
			{
				cnt++;
				if(!vi[cur] && v[cur].size()>0) 
				{
					g[i].push_back(cur);
					w[i].push_back(cnt);
					vi[cur]=true;
					c.push_back(cur);
				}
				if(binarna(0,v[cur].size()-1,cur,t)) break;
				cur-=t;
			}
		}
		for(int j=0;j<c.size();j++) vi[c[j]]=false;
		c.clear();
	}
	dijkstra(st);
	if(!vi[en]) dist[en]=-1;
	printf("%d",dist[en]);
}

Compilation message

skyscraper.cpp: In function 'void dijkstra(int)':
skyscraper.cpp:18:9: error: 'en' was not declared in this scope
   if(u==en) return;
         ^~
skyscraper.cpp:18:9: note: suggested alternative: 'yn'
   if(u==en) return;
         ^~
         yn
skyscraper.cpp:19: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:28: error: 'en' was not declared in this scope
  scanf("%d%d%d%d",&st,&t1,&en,&t2);
                            ^~
skyscraper.cpp:34:28: note: suggested alternative: 'n'
  scanf("%d%d%d%d",&st,&t1,&en,&t2);
                            ^~
                            n
skyscraper.cpp:76:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<c.size();j++) vi[c[j]]=false;
               ~^~~~~~~~~
skyscraper.cpp:33: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:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&t1,&t2);
   ~~~~~^~~~~~~~~~~~~~~~