Submission #882685

# Submission time Handle Problem Language Result Execution time Memory
882685 2023-12-03T13:04:27 Z aeg Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 21716 KB
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
using namespace std;

const int MAXM = 3e4+5, MAXN = 3e4+5;

int n, p[MAXM], m, secloc;
vector<int> a(MAXN, INT_MAX);
queue<int> b[MAXN];

struct triple {
	int first, second;
	char third;
	triple() : first(0), second(0), third(0) {}
	triple(int a, int b, char c) :first(a), second(b), third(c) {}
};

queue<triple> curr, oth;

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		int tmp;
		cin >> tmp >> p[i];
		if(i==0) curr.push({tmp, p[0], 3});
		b[tmp].push(i);
		if(i==1) secloc = tmp;
	}
	int curval = 0;
	while(!curr.empty()) {
		auto cur = curr.front(); curr.pop();
		if(a[cur.first] == INT_MAX) {
			while(!b[cur.first].empty()) {
				int x = b[cur.first].front();
				b[cur.first].pop();
				if(p[x] != cur.second)
					curr.push({cur.first, p[x], 3});
			}
		}
		a[cur.first] = min(a[cur.first], curval);
		if(cur.first >= cur.second && cur.third != 2)
			oth.push({cur.first - cur.second, cur.second, 1});
		if(cur.first < n - cur.second && cur.third != 1)
			oth.push({cur.first + cur.second, cur.second, 2});
		if(curr.empty()) {
			swap(curr, oth);
			curval ++;
		}
	}
	cout << (a[secloc] == INT_MAX ? -1 : a[secloc]) << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 20824 KB Output is correct
2 Correct 13 ms 20572 KB Output is correct
3 Correct 15 ms 20780 KB Output is correct
4 Correct 13 ms 20784 KB Output is correct
5 Correct 11 ms 20576 KB Output is correct
6 Correct 11 ms 20684 KB Output is correct
7 Correct 13 ms 20648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 20572 KB Output is correct
2 Correct 15 ms 20664 KB Output is correct
3 Correct 10 ms 20752 KB Output is correct
4 Correct 11 ms 20572 KB Output is correct
5 Correct 12 ms 20572 KB Output is correct
6 Correct 14 ms 20572 KB Output is correct
7 Correct 13 ms 20664 KB Output is correct
8 Correct 11 ms 20572 KB Output is correct
9 Correct 12 ms 20796 KB Output is correct
10 Correct 12 ms 20796 KB Output is correct
11 Correct 13 ms 20568 KB Output is correct
12 Correct 13 ms 20824 KB Output is correct
13 Correct 14 ms 20804 KB Output is correct
14 Correct 16 ms 20556 KB Output is correct
15 Correct 13 ms 20728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 20572 KB Output is correct
2 Correct 10 ms 20572 KB Output is correct
3 Correct 11 ms 20580 KB Output is correct
4 Correct 11 ms 20668 KB Output is correct
5 Correct 12 ms 20780 KB Output is correct
6 Correct 14 ms 20788 KB Output is correct
7 Correct 13 ms 20584 KB Output is correct
8 Correct 11 ms 20572 KB Output is correct
9 Correct 13 ms 20572 KB Output is correct
10 Correct 11 ms 20572 KB Output is correct
11 Correct 11 ms 20572 KB Output is correct
12 Correct 13 ms 20856 KB Output is correct
13 Correct 11 ms 20652 KB Output is correct
14 Correct 11 ms 20572 KB Output is correct
15 Correct 11 ms 20824 KB Output is correct
16 Correct 11 ms 20568 KB Output is correct
17 Correct 13 ms 20568 KB Output is correct
18 Correct 12 ms 20572 KB Output is correct
19 Correct 11 ms 20568 KB Output is correct
20 Correct 12 ms 20572 KB Output is correct
21 Correct 12 ms 20572 KB Output is correct
22 Correct 13 ms 20572 KB Output is correct
23 Correct 11 ms 20572 KB Output is correct
24 Correct 14 ms 20788 KB Output is correct
25 Correct 15 ms 20800 KB Output is correct
26 Correct 15 ms 20572 KB Output is correct
27 Correct 41 ms 20828 KB Output is correct
28 Correct 13 ms 20572 KB Output is correct
29 Correct 13 ms 20572 KB Output is correct
30 Correct 13 ms 20572 KB Output is correct
31 Correct 15 ms 20652 KB Output is correct
32 Correct 13 ms 20572 KB Output is correct
33 Correct 13 ms 20660 KB Output is correct
34 Correct 15 ms 20640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 20568 KB Output is correct
2 Correct 11 ms 20572 KB Output is correct
3 Correct 12 ms 20572 KB Output is correct
4 Correct 12 ms 20688 KB Output is correct
5 Correct 15 ms 20572 KB Output is correct
6 Correct 13 ms 20572 KB Output is correct
7 Correct 13 ms 20684 KB Output is correct
8 Correct 11 ms 20572 KB Output is correct
9 Correct 12 ms 20788 KB Output is correct
10 Correct 13 ms 20792 KB Output is correct
11 Correct 12 ms 20792 KB Output is correct
12 Correct 14 ms 20748 KB Output is correct
13 Correct 13 ms 20572 KB Output is correct
14 Correct 12 ms 20624 KB Output is correct
15 Correct 12 ms 20764 KB Output is correct
16 Correct 12 ms 20672 KB Output is correct
17 Correct 11 ms 20764 KB Output is correct
18 Correct 16 ms 20792 KB Output is correct
19 Correct 14 ms 20576 KB Output is correct
20 Correct 14 ms 20696 KB Output is correct
21 Correct 12 ms 20580 KB Output is correct
22 Correct 13 ms 20584 KB Output is correct
23 Correct 15 ms 20808 KB Output is correct
24 Correct 12 ms 20580 KB Output is correct
25 Correct 12 ms 20584 KB Output is correct
26 Correct 12 ms 20584 KB Output is correct
27 Correct 39 ms 20840 KB Output is correct
28 Correct 15 ms 20800 KB Output is correct
29 Correct 12 ms 20584 KB Output is correct
30 Correct 14 ms 20584 KB Output is correct
31 Correct 11 ms 20584 KB Output is correct
32 Correct 11 ms 20784 KB Output is correct
33 Correct 11 ms 20840 KB Output is correct
34 Correct 14 ms 20840 KB Output is correct
35 Correct 17 ms 21084 KB Output is correct
36 Correct 11 ms 20772 KB Output is correct
37 Correct 16 ms 21080 KB Output is correct
38 Correct 18 ms 21240 KB Output is correct
39 Correct 17 ms 21084 KB Output is correct
40 Correct 19 ms 21096 KB Output is correct
41 Correct 17 ms 21048 KB Output is correct
42 Correct 17 ms 20892 KB Output is correct
43 Correct 530 ms 21704 KB Output is correct
44 Correct 16 ms 20828 KB Output is correct
45 Correct 24 ms 21084 KB Output is correct
46 Correct 20 ms 21324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 20568 KB Output is correct
2 Correct 11 ms 20572 KB Output is correct
3 Correct 10 ms 20572 KB Output is correct
4 Correct 12 ms 20568 KB Output is correct
5 Correct 10 ms 20572 KB Output is correct
6 Correct 10 ms 20572 KB Output is correct
7 Correct 10 ms 20572 KB Output is correct
8 Correct 16 ms 20568 KB Output is correct
9 Correct 13 ms 20704 KB Output is correct
10 Correct 11 ms 20568 KB Output is correct
11 Correct 10 ms 20572 KB Output is correct
12 Correct 13 ms 20732 KB Output is correct
13 Correct 11 ms 20568 KB Output is correct
14 Correct 11 ms 20572 KB Output is correct
15 Correct 11 ms 20828 KB Output is correct
16 Correct 14 ms 20572 KB Output is correct
17 Correct 11 ms 20568 KB Output is correct
18 Correct 12 ms 20572 KB Output is correct
19 Correct 11 ms 20784 KB Output is correct
20 Correct 12 ms 20568 KB Output is correct
21 Correct 14 ms 20568 KB Output is correct
22 Correct 11 ms 20572 KB Output is correct
23 Correct 11 ms 20572 KB Output is correct
24 Correct 11 ms 20572 KB Output is correct
25 Correct 16 ms 20792 KB Output is correct
26 Correct 14 ms 20568 KB Output is correct
27 Correct 39 ms 20828 KB Output is correct
28 Correct 12 ms 20572 KB Output is correct
29 Correct 11 ms 20572 KB Output is correct
30 Correct 10 ms 20824 KB Output is correct
31 Correct 12 ms 20668 KB Output is correct
32 Correct 11 ms 20572 KB Output is correct
33 Correct 12 ms 20568 KB Output is correct
34 Correct 15 ms 20824 KB Output is correct
35 Correct 20 ms 21084 KB Output is correct
36 Correct 13 ms 20828 KB Output is correct
37 Correct 17 ms 21056 KB Output is correct
38 Correct 17 ms 21084 KB Output is correct
39 Correct 18 ms 21084 KB Output is correct
40 Correct 17 ms 21080 KB Output is correct
41 Correct 17 ms 21236 KB Output is correct
42 Correct 13 ms 20828 KB Output is correct
43 Correct 515 ms 21716 KB Output is correct
44 Correct 15 ms 20828 KB Output is correct
45 Correct 18 ms 21084 KB Output is correct
46 Correct 18 ms 21084 KB Output is correct
47 Correct 26 ms 21336 KB Output is correct
48 Correct 18 ms 20828 KB Output is correct
49 Correct 17 ms 20828 KB Output is correct
50 Correct 14 ms 20828 KB Output is correct
51 Correct 22 ms 21008 KB Output is correct
52 Correct 23 ms 20828 KB Output is correct
53 Correct 22 ms 20828 KB Output is correct
54 Correct 11 ms 20548 KB Output is correct
55 Correct 11 ms 20572 KB Output is correct
56 Correct 17 ms 20824 KB Output is correct
57 Correct 61 ms 20828 KB Output is correct
58 Execution timed out 1072 ms 21596 KB Time limit exceeded
59 Halted 0 ms 0 KB -