Submission #472057

# Submission time Handle Problem Language Result Execution time Memory
472057 2021-09-12T14:21:51 Z hhhhaura Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 241524 KB
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)
 
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i --)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))
 
#define INF 1000000000
using namespace std;
#define pii pair<int, int> 
namespace solver {
	const int P = 4000000;
	const int K = 174;
	int n, m, st, ed, ii;
	vector<int> dis, s;
	vector<pair<int, bool>> mp[P];
	vector<int> a[K][K];
	void init_(int _n, int _m) {
		n = _n, m = _m, ii = n - 1;
		s.clear();
		dis.assign(P, INF);
	}
	void get_new() {
		ii++;
		if(ii >= P) exit(0);
	}
	void add_node(int pos, int b) {
		for(int i = pos % b; i < n; i += b) {
			get_new();
			if(i == pos) mp[i].push_back({ii, 0});
			if(i != pos % b) {
				mp[ii].push_back({ii - 1, 1});
				mp[ii - 1].push_back({ii, 1});
			}
			mp[ii].push_back({i, 0});
		}
	}
	int solve() {
		rep(i, 1, K - 1) rep(j, 0, i - 1) {
			if(!a[i][j].size()) continue;
			sort(all(a[i][j]));
			vector<int> &v = a[i][j];
			int id = -1;
			for(int k = j; k < n; k += i) {
				get_new();
				while(id + 1 < v.size() && v[id + 1] <= k) id ++;
				if(id >= 0 && v[id] == k) mp[k].push_back({ii, 0});
				if(k != j) {
					mp[ii].push_back({ii - 1, 1});
					mp[ii - 1].push_back({ii, 1});
				}
				mp[ii].push_back({k, 0});
			}
		}
		dis[st] = 0;
		deque<int> q;
		q.push_back(st);
		while(q.size()) {
			int cur = q.front();
			q.pop_front();
			for(auto i : mp[cur]) if(dis[i.first] == INF) {
				dis[i.first] = i.second + dis[cur];
				if(i.second) q.push_back(i.first);
				else q.push_front(i.first);
				if(i.first == ed) return dis[ed];
			}
		}
		return (dis[ed] == INF ? -1 : dis[ed]);
	}
};
using namespace solver;
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n, m, b, p; 
	cin >> n >> m;
	init_(n, m);
	rep(i, 0, m - 1) {
		cin >> b >> p;
		if(i == 0) st = b;
		if(i == 1) ed = b;
		if(p >= K) add_node(b, p);
		else a[p][b % p].push_back(b);
	} 
	cout << solve() << "\n";
	return 0;
}

Compilation message

skyscraper.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      | 
skyscraper.cpp: In function 'int solver::solve()':
skyscraper.cpp:49:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     while(id + 1 < v.size() && v[id + 1] <= k) id ++;
      |           ~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 62 ms 110532 KB Output is correct
2 Correct 58 ms 110504 KB Output is correct
3 Correct 60 ms 110580 KB Output is correct
4 Correct 60 ms 110564 KB Output is correct
5 Correct 60 ms 110488 KB Output is correct
6 Correct 60 ms 110596 KB Output is correct
7 Correct 59 ms 110480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 110540 KB Output is correct
2 Correct 57 ms 110520 KB Output is correct
3 Correct 59 ms 110592 KB Output is correct
4 Correct 59 ms 110584 KB Output is correct
5 Correct 58 ms 110604 KB Output is correct
6 Correct 59 ms 110668 KB Output is correct
7 Correct 58 ms 110596 KB Output is correct
8 Correct 60 ms 110512 KB Output is correct
9 Correct 60 ms 110528 KB Output is correct
10 Correct 60 ms 110628 KB Output is correct
11 Correct 60 ms 110752 KB Output is correct
12 Correct 59 ms 110596 KB Output is correct
13 Correct 59 ms 110548 KB Output is correct
14 Correct 61 ms 110844 KB Output is correct
15 Correct 61 ms 110908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 110492 KB Output is correct
2 Correct 58 ms 110580 KB Output is correct
3 Correct 59 ms 110532 KB Output is correct
4 Correct 60 ms 110544 KB Output is correct
5 Correct 58 ms 110532 KB Output is correct
6 Correct 58 ms 110600 KB Output is correct
7 Correct 58 ms 110532 KB Output is correct
8 Correct 58 ms 110520 KB Output is correct
9 Correct 59 ms 110584 KB Output is correct
10 Correct 59 ms 110596 KB Output is correct
11 Correct 60 ms 110832 KB Output is correct
12 Correct 57 ms 110616 KB Output is correct
13 Correct 60 ms 110616 KB Output is correct
14 Correct 60 ms 110804 KB Output is correct
15 Correct 61 ms 110916 KB Output is correct
16 Correct 61 ms 110736 KB Output is correct
17 Correct 64 ms 111224 KB Output is correct
18 Correct 61 ms 110836 KB Output is correct
19 Correct 59 ms 110708 KB Output is correct
20 Correct 60 ms 110720 KB Output is correct
21 Correct 59 ms 110692 KB Output is correct
22 Correct 60 ms 110788 KB Output is correct
23 Correct 59 ms 110896 KB Output is correct
24 Correct 66 ms 111180 KB Output is correct
25 Correct 60 ms 110852 KB Output is correct
26 Correct 60 ms 110916 KB Output is correct
27 Correct 60 ms 110888 KB Output is correct
28 Correct 63 ms 111660 KB Output is correct
29 Correct 71 ms 113376 KB Output is correct
30 Correct 64 ms 111300 KB Output is correct
31 Correct 66 ms 112068 KB Output is correct
32 Correct 63 ms 111668 KB Output is correct
33 Correct 84 ms 116252 KB Output is correct
34 Correct 80 ms 116216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 110520 KB Output is correct
2 Correct 65 ms 110568 KB Output is correct
3 Correct 62 ms 110500 KB Output is correct
4 Correct 61 ms 110588 KB Output is correct
5 Correct 62 ms 110596 KB Output is correct
6 Correct 60 ms 110528 KB Output is correct
7 Correct 58 ms 110532 KB Output is correct
8 Correct 60 ms 110592 KB Output is correct
9 Correct 60 ms 110524 KB Output is correct
10 Correct 60 ms 110572 KB Output is correct
11 Correct 59 ms 110788 KB Output is correct
12 Correct 59 ms 110516 KB Output is correct
13 Correct 60 ms 110532 KB Output is correct
14 Correct 60 ms 110868 KB Output is correct
15 Correct 61 ms 110924 KB Output is correct
16 Correct 59 ms 110792 KB Output is correct
17 Correct 63 ms 111196 KB Output is correct
18 Correct 63 ms 110876 KB Output is correct
19 Correct 59 ms 110776 KB Output is correct
20 Correct 61 ms 110740 KB Output is correct
21 Correct 58 ms 110660 KB Output is correct
22 Correct 61 ms 110812 KB Output is correct
23 Correct 60 ms 110848 KB Output is correct
24 Correct 61 ms 111172 KB Output is correct
25 Correct 60 ms 110948 KB Output is correct
26 Correct 61 ms 110892 KB Output is correct
27 Correct 63 ms 110840 KB Output is correct
28 Correct 62 ms 111684 KB Output is correct
29 Correct 70 ms 113432 KB Output is correct
30 Correct 65 ms 111348 KB Output is correct
31 Correct 78 ms 112124 KB Output is correct
32 Correct 64 ms 111712 KB Output is correct
33 Correct 79 ms 116232 KB Output is correct
34 Correct 79 ms 116172 KB Output is correct
35 Correct 80 ms 115252 KB Output is correct
36 Correct 66 ms 111456 KB Output is correct
37 Correct 89 ms 118588 KB Output is correct
38 Correct 90 ms 117904 KB Output is correct
39 Correct 91 ms 117828 KB Output is correct
40 Correct 89 ms 117768 KB Output is correct
41 Correct 90 ms 117772 KB Output is correct
42 Correct 65 ms 111044 KB Output is correct
43 Correct 65 ms 110916 KB Output is correct
44 Correct 64 ms 110852 KB Output is correct
45 Correct 208 ms 133152 KB Output is correct
46 Correct 189 ms 133316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 110532 KB Output is correct
2 Correct 59 ms 110528 KB Output is correct
3 Correct 60 ms 110532 KB Output is correct
4 Correct 59 ms 110568 KB Output is correct
5 Correct 60 ms 110576 KB Output is correct
6 Correct 61 ms 110528 KB Output is correct
7 Correct 61 ms 110532 KB Output is correct
8 Correct 58 ms 110520 KB Output is correct
9 Correct 62 ms 110588 KB Output is correct
10 Correct 60 ms 110636 KB Output is correct
11 Correct 62 ms 110804 KB Output is correct
12 Correct 58 ms 110516 KB Output is correct
13 Correct 61 ms 110672 KB Output is correct
14 Correct 61 ms 110904 KB Output is correct
15 Correct 60 ms 110920 KB Output is correct
16 Correct 58 ms 110768 KB Output is correct
17 Correct 61 ms 111172 KB Output is correct
18 Correct 62 ms 110928 KB Output is correct
19 Correct 61 ms 110824 KB Output is correct
20 Correct 60 ms 110712 KB Output is correct
21 Correct 61 ms 110680 KB Output is correct
22 Correct 60 ms 110780 KB Output is correct
23 Correct 59 ms 110872 KB Output is correct
24 Correct 64 ms 111116 KB Output is correct
25 Correct 65 ms 110928 KB Output is correct
26 Correct 64 ms 110876 KB Output is correct
27 Correct 61 ms 111020 KB Output is correct
28 Correct 62 ms 111652 KB Output is correct
29 Correct 68 ms 113472 KB Output is correct
30 Correct 61 ms 111300 KB Output is correct
31 Correct 63 ms 112100 KB Output is correct
32 Correct 63 ms 111684 KB Output is correct
33 Correct 86 ms 116344 KB Output is correct
34 Correct 77 ms 116164 KB Output is correct
35 Correct 82 ms 115184 KB Output is correct
36 Correct 65 ms 111396 KB Output is correct
37 Correct 94 ms 118496 KB Output is correct
38 Correct 91 ms 117856 KB Output is correct
39 Correct 87 ms 117828 KB Output is correct
40 Correct 87 ms 117732 KB Output is correct
41 Correct 90 ms 117860 KB Output is correct
42 Correct 66 ms 111068 KB Output is correct
43 Correct 67 ms 110916 KB Output is correct
44 Correct 65 ms 110912 KB Output is correct
45 Correct 223 ms 133076 KB Output is correct
46 Correct 187 ms 133060 KB Output is correct
47 Correct 169 ms 145084 KB Output is correct
48 Correct 96 ms 121484 KB Output is correct
49 Correct 85 ms 117212 KB Output is correct
50 Correct 84 ms 117308 KB Output is correct
51 Correct 116 ms 125324 KB Output is correct
52 Correct 125 ms 126600 KB Output is correct
53 Correct 78 ms 114800 KB Output is correct
54 Correct 63 ms 111896 KB Output is correct
55 Correct 68 ms 113168 KB Output is correct
56 Correct 78 ms 113028 KB Output is correct
57 Correct 118 ms 130936 KB Output is correct
58 Correct 78 ms 113796 KB Output is correct
59 Correct 79 ms 115236 KB Output is correct
60 Correct 82 ms 117032 KB Output is correct
61 Correct 79 ms 115636 KB Output is correct
62 Correct 149 ms 133868 KB Output is correct
63 Correct 765 ms 217072 KB Output is correct
64 Execution timed out 1032 ms 241524 KB Time limit exceeded
65 Halted 0 ms 0 KB -