Submission #472045

# Submission time Handle Problem Language Result Execution time Memory
472045 2021-09-12T13:35:50 Z hhhhaura Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
1000 ms 209344 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
#define MOD 1000000007
#define eps (1e-9)

using namespace std;

#define lld long double
#define pii pair<int, int> 
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

#ifdef wiwihorz
#define print(a...) cerr << "Line " << __LINE__ << ": ", kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); }
#else
#define print(...) 0
#define vprint(...) 0
#endif
namespace solver {
	const int P = 5000000;
	const int K = 180;
	int n, m, st, ed, ii;
	vector<int> dis, s;
	vector<vector<pii>> mp;
	vector<vector<vector<int>>> a;
	void init_(int _n, int _m) {
		n = _n, m = _m, ii = n - 1;
		s.clear();
		dis.assign(n, INF);
		mp.assign(n, vector<pii>());
		rep(i, 0, K - 1) a.push_back(vector<vector<int>>(i, vector<int>()));
	}
	void get_new() {
		ii++;
		mp.push_back(vector<pii>());
		dis.push_back(INF);
	}
	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);
			}
		}
		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:23:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   23 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |             ^~~~
skyscraper.cpp:23:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   23 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |                     ^~~~
skyscraper.cpp: In function 'int solver::solve()':
skyscraper.cpp:68:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     while(id + 1 < v.size() && v[id + 1] <= k) id ++;
      |           ~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 652 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 716 KB Output is correct
11 Correct 2 ms 972 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 716 KB Output is correct
14 Correct 2 ms 1100 KB Output is correct
15 Correct 2 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 716 KB Output is correct
11 Correct 2 ms 972 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 716 KB Output is correct
14 Correct 3 ms 1100 KB Output is correct
15 Correct 2 ms 1100 KB Output is correct
16 Correct 2 ms 972 KB Output is correct
17 Correct 5 ms 1728 KB Output is correct
18 Correct 2 ms 1228 KB Output is correct
19 Correct 2 ms 1100 KB Output is correct
20 Correct 2 ms 972 KB Output is correct
21 Correct 1 ms 844 KB Output is correct
22 Correct 2 ms 1228 KB Output is correct
23 Correct 2 ms 1228 KB Output is correct
24 Correct 4 ms 1688 KB Output is correct
25 Correct 3 ms 1356 KB Output is correct
26 Correct 3 ms 1356 KB Output is correct
27 Correct 2 ms 1356 KB Output is correct
28 Correct 6 ms 2456 KB Output is correct
29 Correct 14 ms 5312 KB Output is correct
30 Correct 6 ms 2172 KB Output is correct
31 Correct 8 ms 3736 KB Output is correct
32 Correct 6 ms 2456 KB Output is correct
33 Correct 30 ms 9600 KB Output is correct
34 Correct 29 ms 9628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 716 KB Output is correct
11 Correct 2 ms 972 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 716 KB Output is correct
14 Correct 2 ms 1100 KB Output is correct
15 Correct 2 ms 1100 KB Output is correct
16 Correct 2 ms 972 KB Output is correct
17 Correct 5 ms 1728 KB Output is correct
18 Correct 2 ms 1228 KB Output is correct
19 Correct 2 ms 1100 KB Output is correct
20 Correct 2 ms 972 KB Output is correct
21 Correct 1 ms 844 KB Output is correct
22 Correct 2 ms 1232 KB Output is correct
23 Correct 2 ms 1228 KB Output is correct
24 Correct 4 ms 1688 KB Output is correct
25 Correct 3 ms 1360 KB Output is correct
26 Correct 3 ms 1356 KB Output is correct
27 Correct 3 ms 1360 KB Output is correct
28 Correct 6 ms 2484 KB Output is correct
29 Correct 14 ms 5288 KB Output is correct
30 Correct 5 ms 2064 KB Output is correct
31 Correct 8 ms 3708 KB Output is correct
32 Correct 6 ms 2424 KB Output is correct
33 Correct 29 ms 9608 KB Output is correct
34 Correct 30 ms 9676 KB Output is correct
35 Correct 34 ms 9332 KB Output is correct
36 Correct 6 ms 2300 KB Output is correct
37 Correct 59 ms 13452 KB Output is correct
38 Correct 55 ms 12740 KB Output is correct
39 Correct 57 ms 12780 KB Output is correct
40 Correct 57 ms 12796 KB Output is correct
41 Correct 58 ms 12724 KB Output is correct
42 Correct 8 ms 1484 KB Output is correct
43 Correct 8 ms 1468 KB Output is correct
44 Correct 7 ms 1012 KB Output is correct
45 Correct 176 ms 36444 KB Output is correct
46 Correct 189 ms 36476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 3 ms 972 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 716 KB Output is correct
14 Correct 3 ms 1100 KB Output is correct
15 Correct 2 ms 1100 KB Output is correct
16 Correct 2 ms 972 KB Output is correct
17 Correct 6 ms 1728 KB Output is correct
18 Correct 2 ms 1228 KB Output is correct
19 Correct 2 ms 1080 KB Output is correct
20 Correct 2 ms 972 KB Output is correct
21 Correct 2 ms 844 KB Output is correct
22 Correct 2 ms 1228 KB Output is correct
23 Correct 2 ms 1228 KB Output is correct
24 Correct 4 ms 1688 KB Output is correct
25 Correct 3 ms 1356 KB Output is correct
26 Correct 3 ms 1356 KB Output is correct
27 Correct 3 ms 1356 KB Output is correct
28 Correct 6 ms 2456 KB Output is correct
29 Correct 14 ms 5288 KB Output is correct
30 Correct 6 ms 2064 KB Output is correct
31 Correct 8 ms 3736 KB Output is correct
32 Correct 9 ms 2456 KB Output is correct
33 Correct 34 ms 9684 KB Output is correct
34 Correct 30 ms 9716 KB Output is correct
35 Correct 34 ms 9440 KB Output is correct
36 Correct 6 ms 2300 KB Output is correct
37 Correct 60 ms 13540 KB Output is correct
38 Correct 56 ms 12740 KB Output is correct
39 Correct 56 ms 12764 KB Output is correct
40 Correct 60 ms 12864 KB Output is correct
41 Correct 57 ms 12784 KB Output is correct
42 Correct 8 ms 1484 KB Output is correct
43 Correct 8 ms 1456 KB Output is correct
44 Correct 9 ms 988 KB Output is correct
45 Correct 176 ms 36428 KB Output is correct
46 Correct 177 ms 36488 KB Output is correct
47 Correct 272 ms 55856 KB Output is correct
48 Correct 58 ms 18628 KB Output is correct
49 Correct 36 ms 12020 KB Output is correct
50 Correct 33 ms 12180 KB Output is correct
51 Correct 108 ms 24888 KB Output is correct
52 Correct 126 ms 27060 KB Output is correct
53 Correct 30 ms 8312 KB Output is correct
54 Correct 7 ms 3724 KB Output is correct
55 Correct 12 ms 5516 KB Output is correct
56 Correct 17 ms 4748 KB Output is correct
57 Correct 146 ms 33708 KB Output is correct
58 Correct 20 ms 6540 KB Output is correct
59 Correct 30 ms 11180 KB Output is correct
60 Correct 39 ms 11744 KB Output is correct
61 Correct 35 ms 11008 KB Output is correct
62 Correct 143 ms 46468 KB Output is correct
63 Correct 846 ms 186648 KB Output is correct
64 Execution timed out 1049 ms 209344 KB Time limit exceeded
65 Halted 0 ms 0 KB -