Submission #20862

# Submission time Handle Problem Language Result Execution time Memory
20862 2017-02-26T18:52:41 Z Silver Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 80204 KB
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> LP;
#define N 30004
#define OO int(1e9)
#define mp make_pair
#define pb push_back
vector<P>v[N];
vector<int>g[N];
ll x, y, z, dis[N][303], n, m, res, r, st, en, w, po;
priority_queue<LP, vector<LP>, greater<LP> >q;
LP f;
bool can(int pos)
{
	return pos >= 0 && pos < n;
}
inline void normal_node()
{
	for (auto u : v[x])//normal edge
	if (w + u.second < dis[u.first][0])
		dis[u.first][0] = w + u.second, q.push(mp(dis[u.first][0], mp(u.first, 0)));
	for (auto u : g[x])//power edge
	if (dis[x][u]>w)
		dis[x][u] = w, q.push(mp(w, mp(x, u)));
}
int main()
{
	scanf("%d%d", &n, &m);
	en = n;
	r = sqrt(double(n));
	for (int i = 0; i <= n; i++)
	for (int j = 0; j <= r; j++)
		dis[i][j] = OO;
	for (int i = 0; i < m; i++)
	{
		scanf("%d%d", &x, &y);
		if (i == 0)st = x;
		else if (i == 1)en = x;
		if (y>r)
		{
			for (int i = x - y, j = 1; i >= 0; i -= y, j++)v[x].pb(mp(i, j));
			for (int i = x + y, j = 1; i < n; i += y, j++)v[x].pb(mp(i, j));
		}
		else
			g[x].pb(y);
	}
	dis[st][0] = 0;
	q.push(mp(0, mp(st, 0)));
	for (auto u : g[st])
		dis[st][u] = 0, q.push(mp(0, mp(st, u)));
	while (!q.empty())
	{
		f = q.top();
		q.pop();
		x = f.second.first;
		w = f.first;
		po = f.second.second;
		if (po != 0)//power node
		{
			y = x + po;
			if (can(y) && w + 1 < dis[y][po])dis[y][po] = w + 1, q.push(mp(dis[y][po], mp(y, po)));
			y = x - po;
			if (can(y) && w + 1 < dis[y][po])dis[y][po] = w + 1, q.push(mp(dis[y][po], mp(y, po)));
			if (dis[x][0] > w)dis[x][0] = w, q.push(mp(w, mp(x, 0)));
		}
		else
			normal_node();
	}
	res = OO;
	for (int i = 0; i <= r; i++)res = min(res, dis[en][i]);
	if (res >= OO)res = -1;
	printf("%d\n", res);
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:30:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
                       ^
skyscraper.cpp:38:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &x, &y);
                        ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 38952 KB Output is correct
2 Correct 0 ms 38952 KB Output is correct
3 Correct 0 ms 38952 KB Output is correct
4 Correct 0 ms 38952 KB Output is correct
5 Correct 0 ms 38952 KB Output is correct
6 Correct 0 ms 38952 KB Output is correct
7 Correct 0 ms 38952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 38952 KB Output is correct
2 Correct 0 ms 38952 KB Output is correct
3 Correct 0 ms 38952 KB Output is correct
4 Correct 0 ms 38952 KB Output is correct
5 Correct 0 ms 38952 KB Output is correct
6 Correct 0 ms 38952 KB Output is correct
7 Correct 0 ms 38952 KB Output is correct
8 Correct 0 ms 38952 KB Output is correct
9 Correct 0 ms 38952 KB Output is correct
10 Correct 0 ms 38952 KB Output is correct
11 Correct 0 ms 38952 KB Output is correct
12 Correct 0 ms 38952 KB Output is correct
13 Correct 0 ms 38952 KB Output is correct
14 Correct 0 ms 39084 KB Output is correct
15 Correct 0 ms 39084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 38952 KB Output is correct
2 Correct 0 ms 38952 KB Output is correct
3 Correct 0 ms 38952 KB Output is correct
4 Correct 0 ms 38952 KB Output is correct
5 Correct 0 ms 38952 KB Output is correct
6 Correct 0 ms 38952 KB Output is correct
7 Correct 0 ms 38952 KB Output is correct
8 Correct 0 ms 38952 KB Output is correct
9 Correct 0 ms 38952 KB Output is correct
10 Correct 0 ms 38952 KB Output is correct
11 Correct 0 ms 38952 KB Output is correct
12 Correct 0 ms 38952 KB Output is correct
13 Correct 0 ms 38952 KB Output is correct
14 Correct 0 ms 39084 KB Output is correct
15 Correct 0 ms 39084 KB Output is correct
16 Correct 0 ms 38952 KB Output is correct
17 Correct 0 ms 39084 KB Output is correct
18 Correct 0 ms 38952 KB Output is correct
19 Correct 3 ms 38952 KB Output is correct
20 Correct 0 ms 39084 KB Output is correct
21 Correct 0 ms 38952 KB Output is correct
22 Correct 0 ms 38952 KB Output is correct
23 Correct 3 ms 38952 KB Output is correct
24 Correct 3 ms 39084 KB Output is correct
25 Correct 0 ms 38952 KB Output is correct
26 Correct 3 ms 38952 KB Output is correct
27 Correct 0 ms 38952 KB Output is correct
28 Correct 3 ms 39084 KB Output is correct
29 Correct 9 ms 38952 KB Output is correct
30 Correct 3 ms 38952 KB Output is correct
31 Correct 6 ms 39104 KB Output is correct
32 Correct 3 ms 39232 KB Output is correct
33 Correct 13 ms 39684 KB Output is correct
34 Correct 9 ms 39688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 38952 KB Output is correct
2 Correct 0 ms 38952 KB Output is correct
3 Correct 0 ms 38952 KB Output is correct
4 Correct 0 ms 38952 KB Output is correct
5 Correct 0 ms 38952 KB Output is correct
6 Correct 0 ms 38952 KB Output is correct
7 Correct 0 ms 38952 KB Output is correct
8 Correct 0 ms 38952 KB Output is correct
9 Correct 0 ms 38952 KB Output is correct
10 Correct 0 ms 38952 KB Output is correct
11 Correct 0 ms 38952 KB Output is correct
12 Correct 0 ms 38952 KB Output is correct
13 Correct 0 ms 38952 KB Output is correct
14 Correct 0 ms 39084 KB Output is correct
15 Correct 0 ms 39084 KB Output is correct
16 Correct 0 ms 38952 KB Output is correct
17 Correct 3 ms 39084 KB Output is correct
18 Correct 3 ms 38952 KB Output is correct
19 Correct 0 ms 38952 KB Output is correct
20 Correct 3 ms 39084 KB Output is correct
21 Correct 0 ms 38952 KB Output is correct
22 Correct 0 ms 38952 KB Output is correct
23 Correct 3 ms 38952 KB Output is correct
24 Correct 3 ms 39084 KB Output is correct
25 Correct 0 ms 38952 KB Output is correct
26 Correct 0 ms 38952 KB Output is correct
27 Correct 0 ms 38952 KB Output is correct
28 Correct 0 ms 39084 KB Output is correct
29 Correct 9 ms 38952 KB Output is correct
30 Correct 3 ms 38952 KB Output is correct
31 Correct 3 ms 39104 KB Output is correct
32 Correct 0 ms 39232 KB Output is correct
33 Correct 9 ms 39684 KB Output is correct
34 Correct 9 ms 39688 KB Output is correct
35 Correct 13 ms 39752 KB Output is correct
36 Correct 3 ms 39084 KB Output is correct
37 Correct 16 ms 40416 KB Output is correct
38 Correct 19 ms 40140 KB Output is correct
39 Correct 16 ms 40144 KB Output is correct
40 Correct 23 ms 40140 KB Output is correct
41 Correct 23 ms 40140 KB Output is correct
42 Correct 0 ms 39228 KB Output is correct
43 Correct 6 ms 39236 KB Output is correct
44 Correct 6 ms 39224 KB Output is correct
45 Correct 23 ms 43516 KB Output is correct
46 Correct 23 ms 43364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 38952 KB Output is correct
2 Correct 0 ms 38952 KB Output is correct
3 Correct 0 ms 38952 KB Output is correct
4 Correct 0 ms 38952 KB Output is correct
5 Correct 0 ms 38952 KB Output is correct
6 Correct 0 ms 38952 KB Output is correct
7 Correct 0 ms 38952 KB Output is correct
8 Correct 0 ms 38952 KB Output is correct
9 Correct 0 ms 38952 KB Output is correct
10 Correct 0 ms 38952 KB Output is correct
11 Correct 0 ms 38952 KB Output is correct
12 Correct 0 ms 38952 KB Output is correct
13 Correct 0 ms 38952 KB Output is correct
14 Correct 0 ms 39084 KB Output is correct
15 Correct 0 ms 39084 KB Output is correct
16 Correct 0 ms 38952 KB Output is correct
17 Correct 0 ms 39084 KB Output is correct
18 Correct 0 ms 38952 KB Output is correct
19 Correct 0 ms 38952 KB Output is correct
20 Correct 0 ms 39084 KB Output is correct
21 Correct 0 ms 38952 KB Output is correct
22 Correct 0 ms 38952 KB Output is correct
23 Correct 0 ms 38952 KB Output is correct
24 Correct 0 ms 39084 KB Output is correct
25 Correct 3 ms 38952 KB Output is correct
26 Correct 3 ms 38952 KB Output is correct
27 Correct 3 ms 38952 KB Output is correct
28 Correct 3 ms 39084 KB Output is correct
29 Correct 6 ms 38952 KB Output is correct
30 Correct 3 ms 38952 KB Output is correct
31 Correct 6 ms 39104 KB Output is correct
32 Correct 3 ms 39232 KB Output is correct
33 Correct 13 ms 39684 KB Output is correct
34 Correct 9 ms 39688 KB Output is correct
35 Correct 9 ms 39752 KB Output is correct
36 Correct 3 ms 39084 KB Output is correct
37 Correct 16 ms 40416 KB Output is correct
38 Correct 16 ms 40140 KB Output is correct
39 Correct 19 ms 40144 KB Output is correct
40 Correct 19 ms 40140 KB Output is correct
41 Correct 19 ms 40140 KB Output is correct
42 Correct 3 ms 39228 KB Output is correct
43 Correct 6 ms 39236 KB Output is correct
44 Correct 6 ms 39224 KB Output is correct
45 Correct 23 ms 43516 KB Output is correct
46 Correct 19 ms 43364 KB Output is correct
47 Correct 96 ms 43912 KB Output is correct
48 Correct 9 ms 40140 KB Output is correct
49 Correct 13 ms 39876 KB Output is correct
50 Correct 9 ms 39744 KB Output is correct
51 Correct 59 ms 41244 KB Output is correct
52 Correct 66 ms 41276 KB Output is correct
53 Correct 16 ms 39084 KB Output is correct
54 Correct 3 ms 38952 KB Output is correct
55 Correct 9 ms 38952 KB Output is correct
56 Correct 16 ms 39876 KB Output is correct
57 Correct 93 ms 39084 KB Output is correct
58 Correct 13 ms 39224 KB Output is correct
59 Correct 26 ms 39224 KB Output is correct
60 Correct 26 ms 39484 KB Output is correct
61 Correct 19 ms 39368 KB Output is correct
62 Correct 59 ms 41328 KB Output is correct
63 Correct 93 ms 67064 KB Output is correct
64 Correct 103 ms 80204 KB Output is correct
65 Correct 343 ms 77212 KB Output is correct
66 Execution timed out 1000 ms 73200 KB Execution timed out
67 Halted 0 ms 0 KB -