Submission #60479

# Submission time Handle Problem Language Result Execution time Memory
60479 2018-07-24T08:44:51 Z Eae02 Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
1000 ms 93804 KB
#include <bits/stdc++.h>

#pragma GCC optimize ("O3")

#pragma pack(push, 1)
struct QEntry
{
	uint16_t building;
	uint16_t doge;
	int cost;
};
#pragma pack(pop)

std::bitset<30000> visited[30000];

int main()
{
	int numBuildings, numDoges;
	std::cin >> numBuildings;
	std::cin >> numDoges;
	
	std::vector<std::vector<int>> dogesInBuildings(numBuildings);
	
	std::vector<int> dogePositions(numDoges);
	std::vector<int> dogePowers(numDoges);
	for (int i = 0; i < numDoges; i++)
	{
		std::cin >> dogePositions[i];
		std::cin >> dogePowers[i];
		
		dogesInBuildings[dogePositions[i]].push_back(i);
	}
	
	std::deque<QEntry> q;
	
	q.push_back(QEntry { dogePositions[0], 0, 0 });
	visited[dogePositions[0]][0] = true;
	
	while (!q.empty())
	{
		QEntry entry = q.front();
		q.pop_front();
		
		if (entry.doge == 1)
		{
			std::cout << entry.cost << std::endl;
			return 0;
		}
		
		for (int d : dogesInBuildings[entry.building])
		{
			if (!visited[entry.building][d])
			{
				visited[entry.building][d] = true;
				q.push_front(QEntry { entry.building, d, entry.cost });
				break;
			}
		}
		
		int pBuilding = (int)entry.building - dogePowers[entry.doge];
		if (pBuilding >= 0 && !visited[pBuilding][entry.doge])
		{
			visited[pBuilding][entry.doge] = true;
			q.push_back(QEntry { pBuilding, entry.doge, entry.cost + 1 });
		}
		
		int nBuilding = (int)entry.building + dogePowers[entry.doge];
		if (nBuilding < numBuildings && !visited[nBuilding][entry.doge])
		{
			visited[nBuilding][entry.doge] = true;
			q.push_back(QEntry { nBuilding, entry.doge, entry.cost + 1 });
		}
	}
	
	std::cout << "-1" << std::endl;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:36:46: warning: narrowing conversion of 'dogePositions.std::vector<int>::operator[](0)' from '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}' to 'uint16_t {aka short unsigned int}' inside { } [-Wnarrowing]
  q.push_back(QEntry { dogePositions[0], 0, 0 });
                                              ^
skyscraper.cpp:55:57: warning: narrowing conversion of 'd' from 'int' to 'uint16_t {aka short unsigned int}' inside { } [-Wnarrowing]
     q.push_front(QEntry { entry.building, d, entry.cost });
                                                         ^
skyscraper.cpp:64:63: warning: narrowing conversion of 'pBuilding' from 'int' to 'uint16_t {aka short unsigned int}' inside { } [-Wnarrowing]
    q.push_back(QEntry { pBuilding, entry.doge, entry.cost + 1 });
                                                               ^
skyscraper.cpp:71:63: warning: narrowing conversion of 'nBuilding' from 'int' to 'uint16_t {aka short unsigned int}' inside { } [-Wnarrowing]
    q.push_back(QEntry { nBuilding, entry.doge, entry.cost + 1 });
                                                               ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 3 ms 392 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 4 ms 852 KB Output is correct
11 Correct 6 ms 980 KB Output is correct
12 Correct 6 ms 980 KB Output is correct
13 Correct 9 ms 1004 KB Output is correct
14 Correct 5 ms 1004 KB Output is correct
15 Correct 6 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1004 KB Output is correct
2 Correct 3 ms 1004 KB Output is correct
3 Correct 2 ms 1004 KB Output is correct
4 Correct 3 ms 1004 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 2 ms 1004 KB Output is correct
7 Correct 3 ms 1004 KB Output is correct
8 Correct 2 ms 1004 KB Output is correct
9 Correct 2 ms 1004 KB Output is correct
10 Correct 4 ms 1004 KB Output is correct
11 Correct 4 ms 1004 KB Output is correct
12 Correct 4 ms 1004 KB Output is correct
13 Correct 8 ms 1004 KB Output is correct
14 Correct 5 ms 1004 KB Output is correct
15 Correct 3 ms 1004 KB Output is correct
16 Correct 4 ms 1004 KB Output is correct
17 Correct 9 ms 3308 KB Output is correct
18 Correct 4 ms 3308 KB Output is correct
19 Correct 2 ms 3308 KB Output is correct
20 Correct 101 ms 8044 KB Output is correct
21 Correct 3 ms 8044 KB Output is correct
22 Correct 3 ms 8044 KB Output is correct
23 Correct 11 ms 8044 KB Output is correct
24 Correct 11 ms 8044 KB Output is correct
25 Correct 8 ms 8044 KB Output is correct
26 Correct 12 ms 8044 KB Output is correct
27 Correct 12 ms 8044 KB Output is correct
28 Correct 13 ms 8044 KB Output is correct
29 Correct 15 ms 8044 KB Output is correct
30 Correct 13 ms 8044 KB Output is correct
31 Correct 14 ms 8044 KB Output is correct
32 Correct 17 ms 8044 KB Output is correct
33 Correct 17 ms 8048 KB Output is correct
34 Correct 14 ms 8048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8048 KB Output is correct
2 Correct 3 ms 8048 KB Output is correct
3 Correct 2 ms 8048 KB Output is correct
4 Correct 2 ms 8048 KB Output is correct
5 Correct 3 ms 8048 KB Output is correct
6 Correct 3 ms 8048 KB Output is correct
7 Correct 3 ms 8048 KB Output is correct
8 Correct 2 ms 8048 KB Output is correct
9 Correct 3 ms 8048 KB Output is correct
10 Correct 3 ms 8048 KB Output is correct
11 Correct 6 ms 8048 KB Output is correct
12 Correct 4 ms 8048 KB Output is correct
13 Correct 8 ms 8048 KB Output is correct
14 Correct 4 ms 8048 KB Output is correct
15 Correct 4 ms 8048 KB Output is correct
16 Correct 4 ms 8048 KB Output is correct
17 Correct 9 ms 8048 KB Output is correct
18 Correct 3 ms 8048 KB Output is correct
19 Correct 2 ms 8048 KB Output is correct
20 Correct 135 ms 8048 KB Output is correct
21 Correct 3 ms 8048 KB Output is correct
22 Correct 4 ms 8048 KB Output is correct
23 Correct 10 ms 8048 KB Output is correct
24 Correct 16 ms 8048 KB Output is correct
25 Correct 6 ms 8048 KB Output is correct
26 Correct 14 ms 8048 KB Output is correct
27 Correct 12 ms 8048 KB Output is correct
28 Correct 18 ms 8048 KB Output is correct
29 Correct 15 ms 8048 KB Output is correct
30 Correct 13 ms 8048 KB Output is correct
31 Correct 13 ms 8048 KB Output is correct
32 Correct 12 ms 8048 KB Output is correct
33 Correct 20 ms 8048 KB Output is correct
34 Correct 20 ms 8048 KB Output is correct
35 Correct 53 ms 8048 KB Output is correct
36 Correct 9 ms 8048 KB Output is correct
37 Correct 33 ms 8172 KB Output is correct
38 Correct 39 ms 8556 KB Output is correct
39 Correct 28 ms 8556 KB Output is correct
40 Correct 30 ms 8556 KB Output is correct
41 Correct 37 ms 8556 KB Output is correct
42 Correct 38 ms 8556 KB Output is correct
43 Correct 36 ms 8556 KB Output is correct
44 Execution timed out 1050 ms 9016 KB Time limit exceeded
45 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9016 KB Output is correct
2 Correct 3 ms 9016 KB Output is correct
3 Correct 3 ms 9016 KB Output is correct
4 Correct 3 ms 9016 KB Output is correct
5 Correct 3 ms 9016 KB Output is correct
6 Correct 3 ms 9016 KB Output is correct
7 Correct 2 ms 9016 KB Output is correct
8 Correct 3 ms 9016 KB Output is correct
9 Correct 2 ms 9016 KB Output is correct
10 Correct 4 ms 9016 KB Output is correct
11 Correct 4 ms 9016 KB Output is correct
12 Correct 4 ms 9016 KB Output is correct
13 Correct 9 ms 9016 KB Output is correct
14 Correct 4 ms 9016 KB Output is correct
15 Correct 5 ms 9016 KB Output is correct
16 Correct 3 ms 9016 KB Output is correct
17 Correct 7 ms 9016 KB Output is correct
18 Correct 4 ms 9016 KB Output is correct
19 Correct 4 ms 9016 KB Output is correct
20 Correct 94 ms 9016 KB Output is correct
21 Correct 4 ms 9016 KB Output is correct
22 Correct 3 ms 9016 KB Output is correct
23 Correct 10 ms 9016 KB Output is correct
24 Correct 16 ms 9016 KB Output is correct
25 Correct 6 ms 9016 KB Output is correct
26 Correct 12 ms 9016 KB Output is correct
27 Correct 15 ms 9016 KB Output is correct
28 Correct 18 ms 9016 KB Output is correct
29 Correct 14 ms 9016 KB Output is correct
30 Correct 14 ms 9016 KB Output is correct
31 Correct 14 ms 9016 KB Output is correct
32 Correct 16 ms 9016 KB Output is correct
33 Correct 18 ms 9016 KB Output is correct
34 Correct 16 ms 9016 KB Output is correct
35 Correct 35 ms 9016 KB Output is correct
36 Correct 9 ms 9016 KB Output is correct
37 Correct 33 ms 9016 KB Output is correct
38 Correct 40 ms 9016 KB Output is correct
39 Correct 29 ms 9016 KB Output is correct
40 Correct 34 ms 9016 KB Output is correct
41 Correct 38 ms 9016 KB Output is correct
42 Correct 32 ms 9016 KB Output is correct
43 Correct 32 ms 9016 KB Output is correct
44 Correct 941 ms 9016 KB Output is correct
45 Correct 94 ms 9016 KB Output is correct
46 Correct 73 ms 9016 KB Output is correct
47 Correct 70 ms 33004 KB Output is correct
48 Correct 35 ms 33004 KB Output is correct
49 Correct 25 ms 33004 KB Output is correct
50 Correct 19 ms 33004 KB Output is correct
51 Correct 142 ms 86508 KB Output is correct
52 Correct 179 ms 93804 KB Output is correct
53 Correct 75 ms 93804 KB Output is correct
54 Correct 87 ms 93804 KB Output is correct
55 Correct 103 ms 93804 KB Output is correct
56 Execution timed out 1067 ms 93804 KB Time limit exceeded
57 Halted 0 ms 0 KB -