Submission #45534

# Submission time Handle Problem Language Result Execution time Memory
45534 2018-04-15T05:14:04 Z gnoor Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
859 ms 5816 KB
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>

using namespace std;

vector<int> pth[30100];
int dis[30100];

struct ei {
	int x,dis;
};

bool operator< (const ei &a, const ei &b) {
	return a.dis>b.dis;
}

int main () {
	int n,m;
	scanf("%d%d",&n,&m);
	int a,b;
	int s,t;
	for (int i=0;i<m;i++) {
		scanf("%d%d",&a,&b);
		pth[a].push_back(b);
		if (i==0) s=a;
		if (i==1) t=a;
	}
	for (int i=0;i<n;i++) {
		sort(pth[i].begin(),pth[i].end());
		pth[i].erase(unique(pth[i].begin(),pth[i].end()),pth[i].end());
	}
	memset(dis,63,sizeof(dis));
	dis[s]=0;
	priority_queue<ei> q;
	q.push(ei{s,0});
	int now,nowdis;
	while (!q.empty()) {
		now = q.top().x;
		nowdis = q.top().dis;
		q.pop();
		if (dis[now]<nowdis) continue;
		if (now==t) {
			printf("%d\n",dis[now]);
			return 0;
		}
		for (auto p:pth[now]) {
			for (int i=1;now+i*p<n;i++) {
				if (dis[now+i*p]<=nowdis+i) continue;
				dis[now+i*p]=nowdis+i;
				q.push(ei{now+i*p,nowdis+i});
			}
			for (int i=1;now-i*p>=0;i++) {
				if (dis[now-i*p]<=nowdis+i) continue;
				dis[now-i*p]=nowdis+i;
				q.push(ei{now-i*p,nowdis+i});
			}
		}
	}
	printf("-1\n");
	return 0;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:22: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:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&a,&b);
   ~~~~~^~~~~~~~~~~~~~
skyscraper.cpp:45:3: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if (now==t) {
   ^~
skyscraper.cpp:38:9: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
  q.push(ei{s,0});
         ^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1144 KB Output is correct
2 Correct 3 ms 1252 KB Output is correct
3 Correct 2 ms 1252 KB Output is correct
4 Correct 2 ms 1252 KB Output is correct
5 Correct 3 ms 1376 KB Output is correct
6 Correct 3 ms 1376 KB Output is correct
7 Correct 2 ms 1532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1532 KB Output is correct
2 Correct 2 ms 1532 KB Output is correct
3 Correct 2 ms 1532 KB Output is correct
4 Correct 2 ms 1532 KB Output is correct
5 Correct 2 ms 1532 KB Output is correct
6 Correct 2 ms 1532 KB Output is correct
7 Correct 2 ms 1532 KB Output is correct
8 Correct 2 ms 1532 KB Output is correct
9 Correct 2 ms 1532 KB Output is correct
10 Correct 2 ms 1532 KB Output is correct
11 Correct 3 ms 1532 KB Output is correct
12 Correct 3 ms 1532 KB Output is correct
13 Correct 3 ms 1532 KB Output is correct
14 Correct 3 ms 1532 KB Output is correct
15 Correct 3 ms 1532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1532 KB Output is correct
2 Correct 2 ms 1532 KB Output is correct
3 Correct 2 ms 1532 KB Output is correct
4 Correct 2 ms 1532 KB Output is correct
5 Correct 2 ms 1532 KB Output is correct
6 Correct 2 ms 1532 KB Output is correct
7 Correct 2 ms 1532 KB Output is correct
8 Correct 2 ms 1532 KB Output is correct
9 Correct 2 ms 1532 KB Output is correct
10 Correct 2 ms 1532 KB Output is correct
11 Correct 3 ms 1532 KB Output is correct
12 Correct 3 ms 1532 KB Output is correct
13 Correct 3 ms 1532 KB Output is correct
14 Correct 3 ms 1532 KB Output is correct
15 Correct 3 ms 1532 KB Output is correct
16 Correct 2 ms 1532 KB Output is correct
17 Correct 3 ms 1532 KB Output is correct
18 Correct 3 ms 1532 KB Output is correct
19 Correct 2 ms 1532 KB Output is correct
20 Correct 7 ms 1532 KB Output is correct
21 Correct 3 ms 1532 KB Output is correct
22 Correct 3 ms 1532 KB Output is correct
23 Correct 3 ms 1532 KB Output is correct
24 Correct 3 ms 1532 KB Output is correct
25 Correct 3 ms 1532 KB Output is correct
26 Correct 3 ms 1532 KB Output is correct
27 Correct 3 ms 1532 KB Output is correct
28 Correct 3 ms 1532 KB Output is correct
29 Correct 4 ms 1660 KB Output is correct
30 Correct 3 ms 1660 KB Output is correct
31 Correct 3 ms 1660 KB Output is correct
32 Correct 3 ms 1660 KB Output is correct
33 Correct 6 ms 1772 KB Output is correct
34 Correct 4 ms 1788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1788 KB Output is correct
2 Correct 2 ms 1788 KB Output is correct
3 Correct 2 ms 1788 KB Output is correct
4 Correct 2 ms 1788 KB Output is correct
5 Correct 2 ms 1788 KB Output is correct
6 Correct 2 ms 1788 KB Output is correct
7 Correct 2 ms 1788 KB Output is correct
8 Correct 2 ms 1788 KB Output is correct
9 Correct 3 ms 1788 KB Output is correct
10 Correct 2 ms 1788 KB Output is correct
11 Correct 3 ms 1788 KB Output is correct
12 Correct 3 ms 1788 KB Output is correct
13 Correct 3 ms 1788 KB Output is correct
14 Correct 3 ms 1788 KB Output is correct
15 Correct 3 ms 1788 KB Output is correct
16 Correct 3 ms 1788 KB Output is correct
17 Correct 3 ms 1788 KB Output is correct
18 Correct 3 ms 1788 KB Output is correct
19 Correct 3 ms 1788 KB Output is correct
20 Correct 7 ms 1788 KB Output is correct
21 Correct 3 ms 1788 KB Output is correct
22 Correct 2 ms 1788 KB Output is correct
23 Correct 3 ms 1788 KB Output is correct
24 Correct 3 ms 1788 KB Output is correct
25 Correct 3 ms 1788 KB Output is correct
26 Correct 3 ms 1788 KB Output is correct
27 Correct 3 ms 1788 KB Output is correct
28 Correct 4 ms 1788 KB Output is correct
29 Correct 4 ms 1788 KB Output is correct
30 Correct 3 ms 1788 KB Output is correct
31 Correct 4 ms 1788 KB Output is correct
32 Correct 4 ms 1788 KB Output is correct
33 Correct 5 ms 1788 KB Output is correct
34 Correct 4 ms 1788 KB Output is correct
35 Correct 10 ms 1788 KB Output is correct
36 Correct 4 ms 1788 KB Output is correct
37 Correct 9 ms 1788 KB Output is correct
38 Correct 12 ms 1788 KB Output is correct
39 Correct 12 ms 1788 KB Output is correct
40 Correct 12 ms 1788 KB Output is correct
41 Correct 12 ms 1788 KB Output is correct
42 Correct 9 ms 1788 KB Output is correct
43 Correct 9 ms 1788 KB Output is correct
44 Correct 13 ms 1788 KB Output is correct
45 Correct 14 ms 1916 KB Output is correct
46 Correct 19 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1920 KB Output is correct
2 Correct 2 ms 1920 KB Output is correct
3 Correct 2 ms 1920 KB Output is correct
4 Correct 2 ms 1920 KB Output is correct
5 Correct 2 ms 1920 KB Output is correct
6 Correct 2 ms 1920 KB Output is correct
7 Correct 2 ms 1920 KB Output is correct
8 Correct 2 ms 1920 KB Output is correct
9 Correct 3 ms 1920 KB Output is correct
10 Correct 2 ms 1920 KB Output is correct
11 Correct 3 ms 1920 KB Output is correct
12 Correct 3 ms 1920 KB Output is correct
13 Correct 2 ms 1920 KB Output is correct
14 Correct 3 ms 1920 KB Output is correct
15 Correct 3 ms 1920 KB Output is correct
16 Correct 5 ms 1920 KB Output is correct
17 Correct 3 ms 1920 KB Output is correct
18 Correct 3 ms 1920 KB Output is correct
19 Correct 2 ms 1920 KB Output is correct
20 Correct 7 ms 1920 KB Output is correct
21 Correct 3 ms 1920 KB Output is correct
22 Correct 3 ms 1920 KB Output is correct
23 Correct 3 ms 1920 KB Output is correct
24 Correct 3 ms 1920 KB Output is correct
25 Correct 3 ms 1920 KB Output is correct
26 Correct 3 ms 1920 KB Output is correct
27 Correct 3 ms 1920 KB Output is correct
28 Correct 3 ms 1920 KB Output is correct
29 Correct 4 ms 1920 KB Output is correct
30 Correct 3 ms 1920 KB Output is correct
31 Correct 4 ms 1920 KB Output is correct
32 Correct 3 ms 1920 KB Output is correct
33 Correct 5 ms 1920 KB Output is correct
34 Correct 4 ms 1920 KB Output is correct
35 Correct 11 ms 1920 KB Output is correct
36 Correct 4 ms 1920 KB Output is correct
37 Correct 9 ms 1920 KB Output is correct
38 Correct 12 ms 1920 KB Output is correct
39 Correct 12 ms 1920 KB Output is correct
40 Correct 11 ms 1920 KB Output is correct
41 Correct 13 ms 1920 KB Output is correct
42 Correct 10 ms 1920 KB Output is correct
43 Correct 9 ms 1920 KB Output is correct
44 Correct 14 ms 1920 KB Output is correct
45 Correct 14 ms 1920 KB Output is correct
46 Correct 13 ms 1920 KB Output is correct
47 Correct 22 ms 2428 KB Output is correct
48 Correct 11 ms 2428 KB Output is correct
49 Correct 10 ms 2428 KB Output is correct
50 Correct 13 ms 2428 KB Output is correct
51 Correct 21 ms 3064 KB Output is correct
52 Correct 21 ms 3064 KB Output is correct
53 Correct 14 ms 3064 KB Output is correct
54 Correct 4 ms 3064 KB Output is correct
55 Correct 4 ms 3064 KB Output is correct
56 Correct 859 ms 3064 KB Output is correct
57 Correct 6 ms 3064 KB Output is correct
58 Correct 11 ms 3064 KB Output is correct
59 Correct 12 ms 3064 KB Output is correct
60 Correct 15 ms 3064 KB Output is correct
61 Correct 11 ms 3064 KB Output is correct
62 Correct 16 ms 3064 KB Output is correct
63 Correct 33 ms 3064 KB Output is correct
64 Correct 40 ms 3700 KB Output is correct
65 Correct 41 ms 3956 KB Output is correct
66 Correct 116 ms 5816 KB Output is correct
67 Correct 52 ms 5816 KB Output is correct