답안 #60549

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
60549 2018-07-24T10:29:14 Z Eae02 Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 240508 KB
#include <bits/stdc++.h>

#pragma GCC optimize("O3")

#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)

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

int main()
{
	int numBuildings, numDoges;
	std::cin >> numBuildings;
	std::cin >> numDoges;
	
	std::vector<std::vector<int>> dogesInBuildings(numBuildings);
	for (int i = 0; i < numBuildings; i++)
		dogesInBuildings[i].reserve(numDoges);
	
	std::set<int> filledBuildings;
	
	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 && (i == 1 || dogePositions[i] - dogePowers[i] >= 0 || dogePositions[i] + dogePowers[i] < numBuildings))
		{
			dogesInBuildings[dogePositions[i]].push_back(i);
			
			filledBuildings.insert(dogePositions[i]);
		}
	}
	
	std::queue<QEntry> q;
	
	q.push(QEntry { dogePositions[0], 0, 0, true });
	q.push(QEntry { dogePositions[0], 0, 0, false });
	
	auto MaybePush = [&] (int b, int d, int c, bool l)
	{
		if (!visited[b][d])
		{
			visited[b][d] = true;
			q.push(QEntry { b, d, c, l });
		}
	};
	
	while (!q.empty())
	{
		QEntry entry = q.front();
		q.pop();
		
		if (entry.doge() == 1 || dogePositions[1] == entry.building)
		{
			std::cout << entry.cost << std::endl;
			return 0;
		}
		
		if (!dogesInBuildings[entry.building].empty())
		{
			for (int nextDoge : dogesInBuildings[entry.building])
			{
				if (dogePowers[nextDoge] == dogePowers[entry.doge()])
					continue;
				
				int pBuilding = (int)entry.building - dogePowers[nextDoge];
				if (pBuilding >= 0)
					MaybePush(pBuilding, nextDoge, entry.cost + 1, true);
				
				int nBuilding = (int)entry.building + dogePowers[nextDoge];
				if (nBuilding < numBuildings)
					MaybePush(nBuilding, nextDoge, entry.cost + 1, false);
			}
			dogesInBuildings[entry.building].clear();
			filledBuildings.erase(entry.building);
		}
		
		if (entry.left())
		{
			int pBuilding = (int)entry.building - dogePowers[entry.doge()];
			if (pBuilding >= 0)
			{
				if (*filledBuildings.begin() <= pBuilding)
				{
					MaybePush(pBuilding, entry.doge(), entry.cost + 1, true);
				}
			}
		}
		else
		{
			int nBuilding = (int)entry.building + dogePowers[entry.doge()];
			if (nBuilding < numBuildings)
			{
				if (*std::prev(filledBuildings.end()) >= nBuilding)
				{
					MaybePush(nBuilding, entry.doge(), entry.cost + 1, false);
				}
			}
		}
	}
	
	std::cout << "-1" << std::endl;
}

Compilation message

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:62:47: 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(QEntry { dogePositions[0], 0, 0, true });
                                               ^
skyscraper.cpp:63:48: 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(QEntry { dogePositions[0], 0, 0, false });
                                                ^
skyscraper.cpp: In lambda function:
skyscraper.cpp:70:31: warning: narrowing conversion of 'b' from 'int' to 'uint16_t {aka short unsigned int}' inside { } [-Wnarrowing]
    q.push(QEntry { b, d, c, l });
                               ^
skyscraper.cpp:70:31: warning: narrowing conversion of 'd' from 'int' to 'uint16_t {aka short unsigned int}' inside { } [-Wnarrowing]
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 540 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Correct 2 ms 608 KB Output is correct
6 Correct 3 ms 608 KB Output is correct
7 Correct 2 ms 608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 608 KB Output is correct
2 Correct 2 ms 608 KB Output is correct
3 Correct 4 ms 608 KB Output is correct
4 Correct 3 ms 608 KB Output is correct
5 Correct 3 ms 608 KB Output is correct
6 Correct 3 ms 608 KB Output is correct
7 Correct 2 ms 608 KB Output is correct
8 Correct 2 ms 608 KB Output is correct
9 Correct 3 ms 608 KB Output is correct
10 Correct 3 ms 1108 KB Output is correct
11 Correct 4 ms 1108 KB Output is correct
12 Correct 3 ms 1232 KB Output is correct
13 Correct 5 ms 1388 KB Output is correct
14 Correct 4 ms 1388 KB Output is correct
15 Correct 5 ms 1388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1388 KB Output is correct
2 Correct 3 ms 1388 KB Output is correct
3 Correct 3 ms 1388 KB Output is correct
4 Correct 3 ms 1388 KB Output is correct
5 Correct 3 ms 1388 KB Output is correct
6 Correct 3 ms 1388 KB Output is correct
7 Correct 3 ms 1388 KB Output is correct
8 Correct 3 ms 1388 KB Output is correct
9 Correct 3 ms 1388 KB Output is correct
10 Correct 3 ms 1388 KB Output is correct
11 Correct 5 ms 1388 KB Output is correct
12 Correct 5 ms 1388 KB Output is correct
13 Correct 5 ms 1388 KB Output is correct
14 Correct 4 ms 1388 KB Output is correct
15 Correct 6 ms 1472 KB Output is correct
16 Correct 3 ms 1472 KB Output is correct
17 Correct 11 ms 6124 KB Output is correct
18 Correct 10 ms 7436 KB Output is correct
19 Correct 6 ms 7436 KB Output is correct
20 Correct 20 ms 16108 KB Output is correct
21 Correct 3 ms 16108 KB Output is correct
22 Correct 6 ms 16108 KB Output is correct
23 Correct 17 ms 16108 KB Output is correct
24 Correct 17 ms 16108 KB Output is correct
25 Correct 14 ms 16108 KB Output is correct
26 Correct 19 ms 16108 KB Output is correct
27 Correct 19 ms 16108 KB Output is correct
28 Correct 23 ms 16108 KB Output is correct
29 Correct 19 ms 16108 KB Output is correct
30 Correct 11 ms 16108 KB Output is correct
31 Correct 15 ms 16108 KB Output is correct
32 Correct 18 ms 16108 KB Output is correct
33 Correct 20 ms 16108 KB Output is correct
34 Correct 19 ms 16108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16108 KB Output is correct
2 Correct 2 ms 16108 KB Output is correct
3 Correct 2 ms 16108 KB Output is correct
4 Correct 2 ms 16108 KB Output is correct
5 Correct 2 ms 16108 KB Output is correct
6 Correct 3 ms 16108 KB Output is correct
7 Correct 2 ms 16108 KB Output is correct
8 Correct 2 ms 16108 KB Output is correct
9 Correct 2 ms 16108 KB Output is correct
10 Correct 3 ms 16108 KB Output is correct
11 Correct 4 ms 16108 KB Output is correct
12 Correct 6 ms 16108 KB Output is correct
13 Correct 6 ms 16108 KB Output is correct
14 Correct 6 ms 16108 KB Output is correct
15 Correct 5 ms 16108 KB Output is correct
16 Correct 4 ms 16108 KB Output is correct
17 Correct 10 ms 16108 KB Output is correct
18 Correct 9 ms 16108 KB Output is correct
19 Correct 7 ms 16108 KB Output is correct
20 Correct 24 ms 16124 KB Output is correct
21 Correct 4 ms 16124 KB Output is correct
22 Correct 7 ms 16124 KB Output is correct
23 Correct 18 ms 16124 KB Output is correct
24 Correct 17 ms 16124 KB Output is correct
25 Correct 14 ms 16124 KB Output is correct
26 Correct 20 ms 16124 KB Output is correct
27 Correct 19 ms 16124 KB Output is correct
28 Correct 24 ms 16124 KB Output is correct
29 Correct 19 ms 16124 KB Output is correct
30 Correct 12 ms 16124 KB Output is correct
31 Correct 13 ms 16124 KB Output is correct
32 Correct 19 ms 16124 KB Output is correct
33 Correct 20 ms 16124 KB Output is correct
34 Correct 21 ms 16124 KB Output is correct
35 Correct 35 ms 16124 KB Output is correct
36 Correct 14 ms 16124 KB Output is correct
37 Correct 51 ms 16252 KB Output is correct
38 Correct 52 ms 17020 KB Output is correct
39 Correct 42 ms 17020 KB Output is correct
40 Correct 42 ms 17020 KB Output is correct
41 Correct 64 ms 17148 KB Output is correct
42 Correct 57 ms 17148 KB Output is correct
43 Correct 43 ms 17148 KB Output is correct
44 Correct 51 ms 17148 KB Output is correct
45 Correct 61 ms 17148 KB Output is correct
46 Correct 56 ms 17148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 17148 KB Output is correct
2 Correct 2 ms 17148 KB Output is correct
3 Correct 2 ms 17148 KB Output is correct
4 Correct 2 ms 17148 KB Output is correct
5 Correct 3 ms 17148 KB Output is correct
6 Correct 2 ms 17148 KB Output is correct
7 Correct 3 ms 17148 KB Output is correct
8 Correct 3 ms 17148 KB Output is correct
9 Correct 4 ms 17148 KB Output is correct
10 Correct 4 ms 17148 KB Output is correct
11 Correct 5 ms 17148 KB Output is correct
12 Correct 5 ms 17148 KB Output is correct
13 Correct 6 ms 17148 KB Output is correct
14 Correct 5 ms 17148 KB Output is correct
15 Correct 6 ms 17148 KB Output is correct
16 Correct 3 ms 17148 KB Output is correct
17 Correct 9 ms 17148 KB Output is correct
18 Correct 11 ms 17148 KB Output is correct
19 Correct 9 ms 17148 KB Output is correct
20 Correct 23 ms 17148 KB Output is correct
21 Correct 5 ms 17148 KB Output is correct
22 Correct 8 ms 17148 KB Output is correct
23 Correct 18 ms 17148 KB Output is correct
24 Correct 21 ms 17148 KB Output is correct
25 Correct 14 ms 17148 KB Output is correct
26 Correct 20 ms 17148 KB Output is correct
27 Correct 19 ms 17148 KB Output is correct
28 Correct 25 ms 17148 KB Output is correct
29 Correct 22 ms 17148 KB Output is correct
30 Correct 14 ms 17148 KB Output is correct
31 Correct 19 ms 17148 KB Output is correct
32 Correct 19 ms 17148 KB Output is correct
33 Correct 25 ms 17148 KB Output is correct
34 Correct 20 ms 17148 KB Output is correct
35 Correct 43 ms 17148 KB Output is correct
36 Correct 12 ms 17148 KB Output is correct
37 Correct 36 ms 17148 KB Output is correct
38 Correct 46 ms 17148 KB Output is correct
39 Correct 37 ms 17148 KB Output is correct
40 Correct 41 ms 17148 KB Output is correct
41 Correct 66 ms 17148 KB Output is correct
42 Correct 48 ms 17148 KB Output is correct
43 Correct 40 ms 17148 KB Output is correct
44 Correct 61 ms 17148 KB Output is correct
45 Correct 63 ms 17148 KB Output is correct
46 Correct 75 ms 17148 KB Output is correct
47 Correct 150 ms 91956 KB Output is correct
48 Correct 132 ms 98940 KB Output is correct
49 Correct 134 ms 107652 KB Output is correct
50 Correct 127 ms 116604 KB Output is correct
51 Correct 286 ms 204796 KB Output is correct
52 Correct 252 ms 213800 KB Output is correct
53 Correct 178 ms 213800 KB Output is correct
54 Correct 7 ms 213800 KB Output is correct
55 Correct 115 ms 213800 KB Output is correct
56 Correct 308 ms 240508 KB Output is correct
57 Correct 114 ms 240508 KB Output is correct
58 Execution timed out 1099 ms 240508 KB Time limit exceeded
59 Halted 0 ms 0 KB -