Submission #472041

# Submission time Handle Problem Language Result Execution time Memory
472041 2021-09-12T13:28:47 Z hhhhaura Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
312 ms 262148 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 = 7000000;
	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(P, INF);
		mp.assign(P, vector<pii>());
		a.assign(K, vector<vector<int>>(K, vector<int>()));
	}
	void get_new() {
		ii++;
		if(ii >= P) while(1);
	}
	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:67:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     while(id + 1 < v.size() && v[id + 1] <= k) id ++;
      |           ~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 103 ms 192836 KB Output is correct
2 Correct 112 ms 192812 KB Output is correct
3 Correct 104 ms 192836 KB Output is correct
4 Correct 106 ms 192836 KB Output is correct
5 Correct 110 ms 192836 KB Output is correct
6 Correct 101 ms 192796 KB Output is correct
7 Correct 104 ms 192864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 192756 KB Output is correct
2 Correct 103 ms 192816 KB Output is correct
3 Correct 107 ms 192848 KB Output is correct
4 Correct 103 ms 192836 KB Output is correct
5 Correct 106 ms 192804 KB Output is correct
6 Correct 104 ms 192804 KB Output is correct
7 Correct 104 ms 192848 KB Output is correct
8 Correct 103 ms 192836 KB Output is correct
9 Correct 103 ms 192880 KB Output is correct
10 Correct 102 ms 192912 KB Output is correct
11 Correct 108 ms 193104 KB Output is correct
12 Correct 103 ms 192840 KB Output is correct
13 Correct 105 ms 192772 KB Output is correct
14 Correct 104 ms 193124 KB Output is correct
15 Correct 103 ms 193092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 192760 KB Output is correct
2 Correct 109 ms 192800 KB Output is correct
3 Correct 103 ms 192752 KB Output is correct
4 Correct 103 ms 192748 KB Output is correct
5 Correct 102 ms 192760 KB Output is correct
6 Correct 105 ms 192852 KB Output is correct
7 Correct 105 ms 192804 KB Output is correct
8 Correct 105 ms 192836 KB Output is correct
9 Correct 104 ms 192740 KB Output is correct
10 Correct 104 ms 192872 KB Output is correct
11 Correct 103 ms 193092 KB Output is correct
12 Correct 107 ms 192768 KB Output is correct
13 Correct 103 ms 192836 KB Output is correct
14 Correct 105 ms 193176 KB Output is correct
15 Correct 106 ms 193092 KB Output is correct
16 Correct 104 ms 192960 KB Output is correct
17 Correct 108 ms 193552 KB Output is correct
18 Correct 105 ms 193156 KB Output is correct
19 Correct 105 ms 192976 KB Output is correct
20 Correct 103 ms 193028 KB Output is correct
21 Correct 105 ms 192996 KB Output is correct
22 Correct 151 ms 193220 KB Output is correct
23 Correct 103 ms 193092 KB Output is correct
24 Correct 109 ms 193380 KB Output is correct
25 Correct 107 ms 193164 KB Output is correct
26 Correct 113 ms 193220 KB Output is correct
27 Correct 106 ms 193140 KB Output is correct
28 Correct 107 ms 193912 KB Output is correct
29 Correct 113 ms 195636 KB Output is correct
30 Correct 106 ms 193664 KB Output is correct
31 Correct 116 ms 194352 KB Output is correct
32 Correct 119 ms 193868 KB Output is correct
33 Correct 129 ms 198468 KB Output is correct
34 Correct 124 ms 198516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 192964 KB Output is correct
2 Correct 104 ms 192768 KB Output is correct
3 Correct 105 ms 192844 KB Output is correct
4 Correct 103 ms 192828 KB Output is correct
5 Correct 108 ms 192836 KB Output is correct
6 Correct 110 ms 192788 KB Output is correct
7 Correct 102 ms 192792 KB Output is correct
8 Correct 104 ms 192856 KB Output is correct
9 Correct 103 ms 192844 KB Output is correct
10 Correct 107 ms 192828 KB Output is correct
11 Correct 108 ms 193092 KB Output is correct
12 Correct 101 ms 192836 KB Output is correct
13 Correct 103 ms 192888 KB Output is correct
14 Correct 107 ms 193124 KB Output is correct
15 Correct 109 ms 193216 KB Output is correct
16 Correct 106 ms 193044 KB Output is correct
17 Correct 104 ms 193476 KB Output is correct
18 Correct 106 ms 193168 KB Output is correct
19 Correct 109 ms 193016 KB Output is correct
20 Correct 110 ms 193092 KB Output is correct
21 Correct 103 ms 192964 KB Output is correct
22 Correct 108 ms 193124 KB Output is correct
23 Correct 104 ms 193092 KB Output is correct
24 Correct 105 ms 193424 KB Output is correct
25 Correct 110 ms 193220 KB Output is correct
26 Correct 108 ms 193116 KB Output is correct
27 Correct 104 ms 193192 KB Output is correct
28 Correct 107 ms 193868 KB Output is correct
29 Correct 119 ms 195656 KB Output is correct
30 Correct 105 ms 193568 KB Output is correct
31 Correct 109 ms 194420 KB Output is correct
32 Correct 107 ms 193860 KB Output is correct
33 Correct 125 ms 198460 KB Output is correct
34 Correct 124 ms 198480 KB Output is correct
35 Correct 134 ms 197664 KB Output is correct
36 Correct 110 ms 193596 KB Output is correct
37 Correct 149 ms 201028 KB Output is correct
38 Correct 145 ms 200388 KB Output is correct
39 Correct 165 ms 200384 KB Output is correct
40 Correct 145 ms 200388 KB Output is correct
41 Correct 149 ms 200392 KB Output is correct
42 Correct 110 ms 193496 KB Output is correct
43 Correct 111 ms 193604 KB Output is correct
44 Correct 111 ms 193372 KB Output is correct
45 Correct 244 ms 215652 KB Output is correct
46 Correct 248 ms 215640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 192756 KB Output is correct
2 Correct 116 ms 192836 KB Output is correct
3 Correct 104 ms 192836 KB Output is correct
4 Correct 103 ms 192860 KB Output is correct
5 Correct 103 ms 192848 KB Output is correct
6 Correct 105 ms 192836 KB Output is correct
7 Correct 103 ms 192756 KB Output is correct
8 Correct 103 ms 192760 KB Output is correct
9 Correct 107 ms 192788 KB Output is correct
10 Correct 105 ms 192836 KB Output is correct
11 Correct 104 ms 193080 KB Output is correct
12 Correct 107 ms 192884 KB Output is correct
13 Correct 102 ms 192776 KB Output is correct
14 Correct 121 ms 193184 KB Output is correct
15 Correct 103 ms 193104 KB Output is correct
16 Correct 103 ms 192964 KB Output is correct
17 Correct 105 ms 193472 KB Output is correct
18 Correct 106 ms 193136 KB Output is correct
19 Correct 107 ms 193160 KB Output is correct
20 Correct 111 ms 193024 KB Output is correct
21 Correct 106 ms 192964 KB Output is correct
22 Correct 105 ms 193132 KB Output is correct
23 Correct 104 ms 193140 KB Output is correct
24 Correct 110 ms 193568 KB Output is correct
25 Correct 104 ms 193092 KB Output is correct
26 Correct 115 ms 193220 KB Output is correct
27 Correct 104 ms 193048 KB Output is correct
28 Correct 111 ms 193932 KB Output is correct
29 Correct 114 ms 195768 KB Output is correct
30 Correct 107 ms 193544 KB Output is correct
31 Correct 106 ms 194372 KB Output is correct
32 Correct 106 ms 193920 KB Output is correct
33 Correct 128 ms 198536 KB Output is correct
34 Correct 124 ms 198484 KB Output is correct
35 Correct 129 ms 197540 KB Output is correct
36 Correct 109 ms 193656 KB Output is correct
37 Correct 149 ms 200772 KB Output is correct
38 Correct 150 ms 200484 KB Output is correct
39 Correct 147 ms 200132 KB Output is correct
40 Correct 147 ms 200152 KB Output is correct
41 Correct 148 ms 200132 KB Output is correct
42 Correct 114 ms 193224 KB Output is correct
43 Correct 111 ms 193260 KB Output is correct
44 Correct 110 ms 193244 KB Output is correct
45 Correct 250 ms 215340 KB Output is correct
46 Correct 246 ms 215408 KB Output is correct
47 Correct 312 ms 227420 KB Output is correct
48 Correct 140 ms 203648 KB Output is correct
49 Correct 130 ms 199536 KB Output is correct
50 Correct 125 ms 199608 KB Output is correct
51 Correct 188 ms 207468 KB Output is correct
52 Correct 193 ms 208928 KB Output is correct
53 Correct 128 ms 197328 KB Output is correct
54 Correct 108 ms 194260 KB Output is correct
55 Correct 111 ms 195428 KB Output is correct
56 Correct 120 ms 195372 KB Output is correct
57 Correct 205 ms 213132 KB Output is correct
58 Correct 117 ms 196036 KB Output is correct
59 Correct 125 ms 197488 KB Output is correct
60 Correct 132 ms 199280 KB Output is correct
61 Correct 131 ms 198016 KB Output is correct
62 Correct 192 ms 216088 KB Output is correct
63 Runtime error 257 ms 262148 KB Execution killed with signal 9
64 Halted 0 ms 0 KB -