Submission #60489

# Submission time Handle Problem Language Result Execution time Memory
60489 2018-07-24T09:04:44 Z Eae02 Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 2668 KB
#include <bits/stdc++.h>

#pragma pack(push, 1)
struct QEntry
{
	uint16_t building;
	uint16_t dogeAndL;
	int cost;
	
	QEntry(uint16_t building, uint16_t doge, int cost, bool left)
	{
		this->building = building;
		this->cost = cost;
		this->dogeAndL = (doge << 1) | (left ? 1 : 0);
	}
	
	bool left()
	{
		return dogeAndL & 0x1;
	}
	
	uint16_t doge()
	{
		return dogeAndL >> 1;
	}
};
#pragma pack(pop)

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];
		
		if (i != 0)
			dogesInBuildings[dogePositions[i]].push_back(i);
	}
	
	std::deque<QEntry> q;
	
	q.push_back(QEntry { dogePositions[0], 0, 0, true });
	q.push_back(QEntry { dogePositions[0], 0, 0, false });
	
	while (!q.empty())
	{
		QEntry entry = q.front();
		q.pop_front();
		
		if (entry.doge() == 1 || dogePositions[1] == entry.building)
		{
			std::cout << entry.cost << std::endl;
			return 0;
		}
		
		for (int nextDoge : dogesInBuildings[entry.building])
		{
			dogesInBuildings[entry.building].pop_back();
			q.push_front(QEntry { entry.building, nextDoge, entry.cost, true });
			q.push_front(QEntry { entry.building, nextDoge, entry.cost, false });
		}
		
		dogesInBuildings[entry.building].clear();
		/*
		if (!dogesInBuildings[entry.building].empty())
		{
			int nextDoge = dogesInBuildings[entry.building].back();
			dogesInBuildings[entry.building].pop_back();
			q.push_front(QEntry { entry.building, nextDoge, entry.cost, true });
			q.push_front(QEntry { entry.building, nextDoge, entry.cost, false });
		}
		*/
		if (entry.left())
		{
			int pBuilding = (int)entry.building - dogePowers[entry.doge()];
			if (pBuilding >= 0)
			{
				q.push_back(QEntry { pBuilding, entry.doge(), entry.cost + 1, true });
			}
		}
		else
		{
			int nBuilding = (int)entry.building + dogePowers[entry.doge()];
			if (nBuilding < numBuildings)
			{
				q.push_back(QEntry { nBuilding, entry.doge(), entry.cost + 1, false });
			}
		}
	}
	
	std::cout << "-1" << std::endl;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:50:52: 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, true });
                                                    ^
skyscraper.cpp:51:53: 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, false });
                                                     ^
skyscraper.cpp:67:69: warning: narrowing conversion of 'nextDoge' from 'int' to 'uint16_t {aka short unsigned int}' inside { } [-Wnarrowing]
    q.push_front(QEntry { entry.building, nextDoge, entry.cost, true });
                                                                     ^
skyscraper.cpp:68:70: warning: narrowing conversion of 'nextDoge' from 'int' to 'uint16_t {aka short unsigned int}' inside { } [-Wnarrowing]
    q.push_front(QEntry { entry.building, nextDoge, entry.cost, false });
                                                                      ^
skyscraper.cpp:86:72: 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, true });
                                                                        ^
skyscraper.cpp:94:73: 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, false });
                                                                         ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 3 ms 564 KB Output is correct
4 Correct 3 ms 592 KB Output is correct
5 Correct 3 ms 592 KB Output is correct
6 Correct 3 ms 700 KB Output is correct
7 Correct 3 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 700 KB Output is correct
2 Correct 3 ms 700 KB Output is correct
3 Correct 3 ms 700 KB Output is correct
4 Correct 3 ms 700 KB Output is correct
5 Correct 2 ms 700 KB Output is correct
6 Correct 3 ms 700 KB Output is correct
7 Correct 3 ms 700 KB Output is correct
8 Correct 3 ms 700 KB Output is correct
9 Correct 1 ms 700 KB Output is correct
10 Correct 3 ms 700 KB Output is correct
11 Correct 4 ms 700 KB Output is correct
12 Correct 4 ms 700 KB Output is correct
13 Correct 5 ms 700 KB Output is correct
14 Correct 5 ms 704 KB Output is correct
15 Correct 6 ms 704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 704 KB Output is correct
2 Correct 3 ms 704 KB Output is correct
3 Correct 3 ms 704 KB Output is correct
4 Correct 3 ms 704 KB Output is correct
5 Correct 2 ms 704 KB Output is correct
6 Correct 2 ms 704 KB Output is correct
7 Correct 3 ms 704 KB Output is correct
8 Correct 3 ms 704 KB Output is correct
9 Correct 3 ms 704 KB Output is correct
10 Correct 3 ms 704 KB Output is correct
11 Correct 4 ms 704 KB Output is correct
12 Correct 4 ms 704 KB Output is correct
13 Correct 4 ms 704 KB Output is correct
14 Correct 4 ms 704 KB Output is correct
15 Correct 5 ms 764 KB Output is correct
16 Correct 3 ms 764 KB Output is correct
17 Correct 4 ms 764 KB Output is correct
18 Correct 4 ms 764 KB Output is correct
19 Correct 4 ms 764 KB Output is correct
20 Correct 56 ms 764 KB Output is correct
21 Correct 4 ms 764 KB Output is correct
22 Correct 3 ms 764 KB Output is correct
23 Correct 4 ms 764 KB Output is correct
24 Correct 4 ms 764 KB Output is correct
25 Correct 4 ms 764 KB Output is correct
26 Correct 4 ms 764 KB Output is correct
27 Correct 5 ms 764 KB Output is correct
28 Correct 7 ms 764 KB Output is correct
29 Correct 4 ms 764 KB Output is correct
30 Correct 3 ms 764 KB Output is correct
31 Correct 4 ms 764 KB Output is correct
32 Correct 4 ms 764 KB Output is correct
33 Correct 6 ms 764 KB Output is correct
34 Correct 6 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 764 KB Output is correct
2 Correct 3 ms 764 KB Output is correct
3 Correct 2 ms 764 KB Output is correct
4 Correct 3 ms 764 KB Output is correct
5 Correct 2 ms 764 KB Output is correct
6 Correct 3 ms 764 KB Output is correct
7 Correct 3 ms 764 KB Output is correct
8 Correct 1 ms 764 KB Output is correct
9 Correct 3 ms 764 KB Output is correct
10 Correct 3 ms 764 KB Output is correct
11 Correct 4 ms 764 KB Output is correct
12 Correct 3 ms 764 KB Output is correct
13 Correct 4 ms 764 KB Output is correct
14 Correct 4 ms 764 KB Output is correct
15 Correct 4 ms 764 KB Output is correct
16 Correct 3 ms 764 KB Output is correct
17 Correct 5 ms 764 KB Output is correct
18 Correct 4 ms 764 KB Output is correct
19 Correct 4 ms 764 KB Output is correct
20 Correct 53 ms 764 KB Output is correct
21 Correct 4 ms 764 KB Output is correct
22 Correct 4 ms 764 KB Output is correct
23 Correct 4 ms 764 KB Output is correct
24 Correct 4 ms 764 KB Output is correct
25 Correct 4 ms 764 KB Output is correct
26 Correct 4 ms 764 KB Output is correct
27 Correct 4 ms 764 KB Output is correct
28 Correct 5 ms 764 KB Output is correct
29 Correct 5 ms 764 KB Output is correct
30 Correct 3 ms 764 KB Output is correct
31 Correct 4 ms 764 KB Output is correct
32 Correct 3 ms 764 KB Output is correct
33 Correct 6 ms 764 KB Output is correct
34 Correct 6 ms 764 KB Output is correct
35 Correct 26 ms 1148 KB Output is correct
36 Correct 6 ms 1148 KB Output is correct
37 Correct 23 ms 1148 KB Output is correct
38 Correct 27 ms 1148 KB Output is correct
39 Correct 27 ms 1148 KB Output is correct
40 Correct 25 ms 1148 KB Output is correct
41 Correct 22 ms 1152 KB Output is correct
42 Correct 21 ms 1152 KB Output is correct
43 Correct 22 ms 1256 KB Output is correct
44 Correct 63 ms 1512 KB Output is correct
45 Correct 37 ms 1512 KB Output is correct
46 Correct 29 ms 1512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1512 KB Output is correct
2 Correct 2 ms 1512 KB Output is correct
3 Correct 3 ms 1512 KB Output is correct
4 Correct 3 ms 1512 KB Output is correct
5 Correct 3 ms 1512 KB Output is correct
6 Correct 3 ms 1512 KB Output is correct
7 Correct 3 ms 1512 KB Output is correct
8 Correct 2 ms 1512 KB Output is correct
9 Correct 2 ms 1512 KB Output is correct
10 Correct 2 ms 1512 KB Output is correct
11 Correct 5 ms 1512 KB Output is correct
12 Correct 3 ms 1512 KB Output is correct
13 Correct 4 ms 1512 KB Output is correct
14 Correct 5 ms 1512 KB Output is correct
15 Correct 4 ms 1512 KB Output is correct
16 Correct 3 ms 1512 KB Output is correct
17 Correct 4 ms 1512 KB Output is correct
18 Correct 3 ms 1512 KB Output is correct
19 Correct 2 ms 1512 KB Output is correct
20 Correct 54 ms 1512 KB Output is correct
21 Correct 5 ms 1512 KB Output is correct
22 Correct 3 ms 1512 KB Output is correct
23 Correct 5 ms 1512 KB Output is correct
24 Correct 5 ms 1512 KB Output is correct
25 Correct 5 ms 1512 KB Output is correct
26 Correct 4 ms 1512 KB Output is correct
27 Correct 4 ms 1512 KB Output is correct
28 Correct 5 ms 1512 KB Output is correct
29 Correct 5 ms 1512 KB Output is correct
30 Correct 3 ms 1512 KB Output is correct
31 Correct 3 ms 1512 KB Output is correct
32 Correct 3 ms 1512 KB Output is correct
33 Correct 5 ms 1512 KB Output is correct
34 Correct 6 ms 1512 KB Output is correct
35 Correct 22 ms 1512 KB Output is correct
36 Correct 7 ms 1512 KB Output is correct
37 Correct 23 ms 1512 KB Output is correct
38 Correct 27 ms 1512 KB Output is correct
39 Correct 43 ms 1512 KB Output is correct
40 Correct 40 ms 1512 KB Output is correct
41 Correct 30 ms 1512 KB Output is correct
42 Correct 26 ms 1512 KB Output is correct
43 Correct 30 ms 1512 KB Output is correct
44 Correct 65 ms 1532 KB Output is correct
45 Correct 39 ms 1532 KB Output is correct
46 Correct 26 ms 1532 KB Output is correct
47 Correct 39 ms 1532 KB Output is correct
48 Correct 26 ms 1916 KB Output is correct
49 Correct 33 ms 1916 KB Output is correct
50 Correct 19 ms 1916 KB Output is correct
51 Correct 41 ms 2140 KB Output is correct
52 Correct 42 ms 2148 KB Output is correct
53 Correct 40 ms 2168 KB Output is correct
54 Correct 4 ms 2168 KB Output is correct
55 Correct 4 ms 2168 KB Output is correct
56 Execution timed out 1057 ms 2668 KB Time limit exceeded
57 Halted 0 ms 0 KB -