Submission #81834

# Submission time Handle Problem Language Result Execution time Memory
81834 2018-10-27T06:13:33 Z antimirage Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
199 ms 65648 KB
#include <bits/stdc++.h>
 
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
 
using namespace std;
 
const int N = 3e4 + 5;
 
int n, m, en, pos, p, d[N], st;
 
set <int, greater <int> > vec[N];

vector < vector <pair <int, int> > > g;
 
priority_queue < pair <int, int> > q;
 
int main() 
{
	cin >> n >> m;
	g.resize(n);
	for (int i = 1; i <= m; i++)
	{
		scanf("%d%d", &pos, &p);
		vec[pos].insert(p);
		if (i == 1)
			st = pos;
		if (i == 2)
			en = pos;
	}
	for (int i = 0; i < n; i++)
	{
		for (auto to : vec[i])
		{
			for (int j = i - to; j >= 0; j -= to)
			{
				g[i].pb(mk(j, (i - j) / to ) );
				if (vec[j].lower_bound(to) != vec[j].end() && *vec[j].lower_bound(to) == to)
					break;
			}
			for (int j = i + to; j < n; j += to)
			{
				g[i].pb(mk(j, (j - i) / to ) );
				if (vec[j].lower_bound(to) != vec[j].end() && *vec[j].lower_bound(to) == to)
					break;
			}
		}
	}
	memset(d, 0x3f3f3f3f, sizeof(d));
	d[st] = 0;
	q.push( mk( 0, st ) );
	
	while (!q.empty())
	{
		int v = q.top().sc, len = -q.top().fr;
		q.pop();
		if (d[v] < len) continue;
		
		for (auto to : g[v])
		{
			if (d[to.fr] > d[v] + to.sc)
			{
				d[to.fr] = d[v] + to.sc;
				q.push( mk( -d[to.fr], to.fr ) );
			}
		}
		
	}
	if (d[en] > 1e9)
		d[en] = -1;
	cout << d[en] << endl;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &pos, &p);
   ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1912 KB Output is correct
2 Correct 3 ms 1916 KB Output is correct
3 Correct 3 ms 1916 KB Output is correct
4 Correct 3 ms 1992 KB Output is correct
5 Correct 3 ms 1992 KB Output is correct
6 Correct 3 ms 2040 KB Output is correct
7 Correct 3 ms 2096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2128 KB Output is correct
2 Correct 3 ms 2152 KB Output is correct
3 Correct 4 ms 2152 KB Output is correct
4 Correct 3 ms 2152 KB Output is correct
5 Correct 3 ms 2152 KB Output is correct
6 Correct 3 ms 2152 KB Output is correct
7 Correct 3 ms 2152 KB Output is correct
8 Correct 3 ms 2152 KB Output is correct
9 Correct 3 ms 2152 KB Output is correct
10 Correct 3 ms 2172 KB Output is correct
11 Correct 4 ms 2276 KB Output is correct
12 Correct 3 ms 2276 KB Output is correct
13 Correct 3 ms 2276 KB Output is correct
14 Correct 4 ms 2276 KB Output is correct
15 Correct 4 ms 2276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2276 KB Output is correct
2 Correct 3 ms 2276 KB Output is correct
3 Correct 3 ms 2276 KB Output is correct
4 Correct 3 ms 2276 KB Output is correct
5 Correct 3 ms 2276 KB Output is correct
6 Correct 3 ms 2276 KB Output is correct
7 Correct 3 ms 2276 KB Output is correct
8 Correct 3 ms 2276 KB Output is correct
9 Correct 3 ms 2276 KB Output is correct
10 Correct 3 ms 2276 KB Output is correct
11 Correct 4 ms 2276 KB Output is correct
12 Correct 4 ms 2276 KB Output is correct
13 Correct 3 ms 2276 KB Output is correct
14 Correct 4 ms 2276 KB Output is correct
15 Correct 4 ms 2276 KB Output is correct
16 Correct 4 ms 2276 KB Output is correct
17 Correct 5 ms 2428 KB Output is correct
18 Correct 4 ms 2428 KB Output is correct
19 Correct 3 ms 2428 KB Output is correct
20 Correct 4 ms 2428 KB Output is correct
21 Correct 4 ms 2428 KB Output is correct
22 Correct 4 ms 2428 KB Output is correct
23 Correct 4 ms 2428 KB Output is correct
24 Correct 5 ms 2428 KB Output is correct
25 Correct 5 ms 2428 KB Output is correct
26 Correct 4 ms 2428 KB Output is correct
27 Correct 4 ms 2428 KB Output is correct
28 Correct 4 ms 2428 KB Output is correct
29 Correct 5 ms 2940 KB Output is correct
30 Correct 4 ms 2940 KB Output is correct
31 Correct 5 ms 2940 KB Output is correct
32 Correct 5 ms 2940 KB Output is correct
33 Correct 7 ms 3496 KB Output is correct
34 Correct 9 ms 3496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3496 KB Output is correct
2 Correct 3 ms 3496 KB Output is correct
3 Correct 3 ms 3496 KB Output is correct
4 Correct 3 ms 3496 KB Output is correct
5 Correct 3 ms 3496 KB Output is correct
6 Correct 3 ms 3496 KB Output is correct
7 Correct 3 ms 3496 KB Output is correct
8 Correct 3 ms 3496 KB Output is correct
9 Correct 3 ms 3496 KB Output is correct
10 Correct 3 ms 3496 KB Output is correct
11 Correct 4 ms 3496 KB Output is correct
12 Correct 4 ms 3496 KB Output is correct
13 Correct 3 ms 3496 KB Output is correct
14 Correct 4 ms 3496 KB Output is correct
15 Correct 4 ms 3496 KB Output is correct
16 Correct 4 ms 3496 KB Output is correct
17 Correct 5 ms 3496 KB Output is correct
18 Correct 4 ms 3496 KB Output is correct
19 Correct 4 ms 3496 KB Output is correct
20 Correct 4 ms 3496 KB Output is correct
21 Correct 4 ms 3496 KB Output is correct
22 Correct 4 ms 3496 KB Output is correct
23 Correct 4 ms 3496 KB Output is correct
24 Correct 5 ms 3496 KB Output is correct
25 Correct 5 ms 3496 KB Output is correct
26 Correct 4 ms 3496 KB Output is correct
27 Correct 4 ms 3496 KB Output is correct
28 Correct 5 ms 3496 KB Output is correct
29 Correct 6 ms 3496 KB Output is correct
30 Correct 4 ms 3496 KB Output is correct
31 Correct 5 ms 3496 KB Output is correct
32 Correct 4 ms 3496 KB Output is correct
33 Correct 7 ms 3496 KB Output is correct
34 Correct 7 ms 3496 KB Output is correct
35 Correct 27 ms 4348 KB Output is correct
36 Correct 6 ms 4348 KB Output is correct
37 Correct 29 ms 5116 KB Output is correct
38 Correct 33 ms 5376 KB Output is correct
39 Correct 34 ms 5376 KB Output is correct
40 Correct 37 ms 5376 KB Output is correct
41 Correct 32 ms 5376 KB Output is correct
42 Correct 9 ms 5376 KB Output is correct
43 Correct 9 ms 5376 KB Output is correct
44 Correct 9 ms 5376 KB Output is correct
45 Correct 30 ms 7676 KB Output is correct
46 Correct 38 ms 7676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7676 KB Output is correct
2 Correct 3 ms 7676 KB Output is correct
3 Correct 3 ms 7676 KB Output is correct
4 Correct 3 ms 7676 KB Output is correct
5 Correct 3 ms 7676 KB Output is correct
6 Correct 3 ms 7676 KB Output is correct
7 Correct 3 ms 7676 KB Output is correct
8 Correct 3 ms 7676 KB Output is correct
9 Correct 3 ms 7676 KB Output is correct
10 Correct 3 ms 7676 KB Output is correct
11 Correct 5 ms 7676 KB Output is correct
12 Correct 3 ms 7676 KB Output is correct
13 Correct 3 ms 7676 KB Output is correct
14 Correct 4 ms 7676 KB Output is correct
15 Correct 4 ms 7676 KB Output is correct
16 Correct 4 ms 7676 KB Output is correct
17 Correct 5 ms 7676 KB Output is correct
18 Correct 4 ms 7676 KB Output is correct
19 Correct 3 ms 7676 KB Output is correct
20 Correct 4 ms 7676 KB Output is correct
21 Correct 3 ms 7676 KB Output is correct
22 Correct 4 ms 7676 KB Output is correct
23 Correct 5 ms 7676 KB Output is correct
24 Correct 5 ms 7676 KB Output is correct
25 Correct 5 ms 7676 KB Output is correct
26 Correct 4 ms 7676 KB Output is correct
27 Correct 4 ms 7676 KB Output is correct
28 Correct 4 ms 7676 KB Output is correct
29 Correct 5 ms 7676 KB Output is correct
30 Correct 4 ms 7676 KB Output is correct
31 Correct 5 ms 7676 KB Output is correct
32 Correct 5 ms 7676 KB Output is correct
33 Correct 7 ms 7676 KB Output is correct
34 Correct 7 ms 7676 KB Output is correct
35 Correct 25 ms 7676 KB Output is correct
36 Correct 6 ms 7676 KB Output is correct
37 Correct 29 ms 7676 KB Output is correct
38 Correct 48 ms 7676 KB Output is correct
39 Correct 36 ms 7676 KB Output is correct
40 Correct 31 ms 7676 KB Output is correct
41 Correct 34 ms 7676 KB Output is correct
42 Correct 14 ms 7676 KB Output is correct
43 Correct 14 ms 7676 KB Output is correct
44 Correct 14 ms 7676 KB Output is correct
45 Correct 31 ms 7676 KB Output is correct
46 Correct 46 ms 7676 KB Output is correct
47 Correct 66 ms 12792 KB Output is correct
48 Correct 25 ms 12792 KB Output is correct
49 Correct 21 ms 12792 KB Output is correct
50 Correct 20 ms 12792 KB Output is correct
51 Correct 57 ms 12792 KB Output is correct
52 Correct 53 ms 12792 KB Output is correct
53 Correct 28 ms 12792 KB Output is correct
54 Correct 6 ms 12792 KB Output is correct
55 Correct 7 ms 12792 KB Output is correct
56 Correct 20 ms 12792 KB Output is correct
57 Correct 50 ms 12792 KB Output is correct
58 Correct 13 ms 12792 KB Output is correct
59 Correct 14 ms 12792 KB Output is correct
60 Correct 16 ms 12792 KB Output is correct
61 Correct 17 ms 12792 KB Output is correct
62 Correct 33 ms 12792 KB Output is correct
63 Correct 95 ms 27100 KB Output is correct
64 Correct 99 ms 30272 KB Output is correct
65 Correct 128 ms 40444 KB Output is correct
66 Correct 199 ms 65488 KB Output is correct
67 Correct 197 ms 65648 KB Output is correct