Submission #18400

# Submission time Handle Problem Language Result Execution time Memory
18400 2016-01-31T07:20:27 Z choyi0521 Jakarta Skyscrapers (APIO15_skyscraper) C++
Compilation error
0 ms 0 KB
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int MAX_N = 30000, RTN = 200;
int n, m, dist[MAX_N], s, e;
bool ck[MAX_N][RTN], fvis[MAX_N];
struct st{
	int b, p, w;
	st(int _b, int _p, int _w)
		:b(_b), p(_p), w(_w){}
};
vector<int> adj[MAX_N];
queue<st> q;
int main(){
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++){
		int a, b;
		scanf("%d %d", &a, &b);
		adj[a].push_back(b);
		if (i == 0) s = a;
		if (i == 1) e = a;
	}
	dist[e] = -1;
	q.push(st(s, 0, 0));
	while (!q.empty()){
		st h = q.front();
		q.pop();
		if (h.b < 0 || h.b >= n) continue;
		if (abs(h.p) < RTN){
			if (ck[h.b][abs(h.p)]) continue;
			ck[h.b][abs(h.p)] = true;
		}
		if (!fvis[h.b]){
			fvis[h.b] = true;
			dist[h.b] = h.w;
			for (auto t : adj[h.b]){
				q.push(st(h.b + t, t, h.w + 1));
				q.push(st(h.b - t, -t, h.w + 1));
			}
		}
		q.push(st(h.b + h.p, h.p, h.w + 1));
	}
	printf("%d", dist[e]);
	return 0;
}

Compilation message

skyscraper.cpp: In function ‘int main()’:
skyscraper.cpp:38:9: warning: ‘auto’ changes meaning in C++11; please remove it [-Wc++0x-compat]
    for (auto t : adj[h.b]){
         ^
skyscraper.cpp:38:14: error: ‘t’ does not name a type
    for (auto t : adj[h.b]){
              ^
skyscraper.cpp:42:3: error: expected ‘;’ before ‘}’ token
   }
   ^
skyscraper.cpp:42:3: error: expected primary-expression before ‘}’ token
skyscraper.cpp:42:3: error: expected ‘;’ before ‘}’ token
skyscraper.cpp:42:3: error: expected primary-expression before ‘}’ token
skyscraper.cpp:42:3: error: expected ‘)’ before ‘}’ token
skyscraper.cpp:42:3: error: expected primary-expression before ‘}’ token
skyscraper.cpp:17:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
                        ^
skyscraper.cpp:20:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a, &b);
                         ^