Submission #472037

# Submission time Handle Problem Language Result Execution time Memory
472037 2021-09-12T13:24:40 Z hhhhaura Jakarta Skyscrapers (APIO15_skyscraper) C++14
57 / 100
335 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 = 8000000;
	const int K = 220;
	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++;
	}
	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:66:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     while(id + 1 < v.size() && v[id + 1] <= k) id ++;
      |           ~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 116 ms 220612 KB Output is correct
2 Correct 117 ms 220544 KB Output is correct
3 Correct 121 ms 220540 KB Output is correct
4 Correct 116 ms 220632 KB Output is correct
5 Correct 118 ms 220604 KB Output is correct
6 Correct 116 ms 220624 KB Output is correct
7 Correct 119 ms 220612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 220628 KB Output is correct
2 Correct 119 ms 220516 KB Output is correct
3 Correct 119 ms 220544 KB Output is correct
4 Correct 116 ms 220548 KB Output is correct
5 Correct 123 ms 220612 KB Output is correct
6 Correct 118 ms 220632 KB Output is correct
7 Correct 115 ms 220592 KB Output is correct
8 Correct 116 ms 220568 KB Output is correct
9 Correct 118 ms 220572 KB Output is correct
10 Correct 120 ms 220716 KB Output is correct
11 Correct 123 ms 220868 KB Output is correct
12 Correct 118 ms 220532 KB Output is correct
13 Correct 117 ms 220612 KB Output is correct
14 Correct 126 ms 220864 KB Output is correct
15 Correct 124 ms 220896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 220624 KB Output is correct
2 Correct 120 ms 220612 KB Output is correct
3 Correct 117 ms 220596 KB Output is correct
4 Correct 121 ms 220580 KB Output is correct
5 Correct 131 ms 220612 KB Output is correct
6 Correct 119 ms 220564 KB Output is correct
7 Correct 120 ms 220564 KB Output is correct
8 Correct 118 ms 220624 KB Output is correct
9 Correct 119 ms 220616 KB Output is correct
10 Correct 122 ms 220800 KB Output is correct
11 Correct 122 ms 220868 KB Output is correct
12 Correct 121 ms 220540 KB Output is correct
13 Correct 116 ms 220540 KB Output is correct
14 Correct 118 ms 220948 KB Output is correct
15 Correct 121 ms 220920 KB Output is correct
16 Correct 120 ms 220728 KB Output is correct
17 Correct 121 ms 221328 KB Output is correct
18 Correct 118 ms 220864 KB Output is correct
19 Correct 117 ms 220880 KB Output is correct
20 Correct 116 ms 220852 KB Output is correct
21 Correct 117 ms 220740 KB Output is correct
22 Correct 121 ms 220844 KB Output is correct
23 Correct 126 ms 220940 KB Output is correct
24 Correct 121 ms 221116 KB Output is correct
25 Correct 123 ms 220956 KB Output is correct
26 Correct 122 ms 220992 KB Output is correct
27 Correct 121 ms 220944 KB Output is correct
28 Correct 123 ms 221732 KB Output is correct
29 Correct 129 ms 223500 KB Output is correct
30 Correct 121 ms 221440 KB Output is correct
31 Correct 122 ms 222192 KB Output is correct
32 Correct 122 ms 221744 KB Output is correct
33 Correct 145 ms 226236 KB Output is correct
34 Correct 138 ms 226260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 220552 KB Output is correct
2 Correct 120 ms 220532 KB Output is correct
3 Correct 123 ms 220612 KB Output is correct
4 Correct 120 ms 220576 KB Output is correct
5 Correct 120 ms 220580 KB Output is correct
6 Correct 117 ms 220564 KB Output is correct
7 Correct 123 ms 220572 KB Output is correct
8 Correct 120 ms 220652 KB Output is correct
9 Correct 122 ms 220648 KB Output is correct
10 Correct 117 ms 220612 KB Output is correct
11 Correct 117 ms 220800 KB Output is correct
12 Correct 119 ms 220660 KB Output is correct
13 Correct 118 ms 220612 KB Output is correct
14 Correct 118 ms 220952 KB Output is correct
15 Correct 121 ms 220944 KB Output is correct
16 Correct 116 ms 220740 KB Output is correct
17 Correct 123 ms 221420 KB Output is correct
18 Correct 118 ms 220868 KB Output is correct
19 Correct 135 ms 220740 KB Output is correct
20 Correct 122 ms 220720 KB Output is correct
21 Correct 117 ms 220712 KB Output is correct
22 Correct 121 ms 220824 KB Output is correct
23 Correct 124 ms 220852 KB Output is correct
24 Correct 121 ms 221124 KB Output is correct
25 Correct 120 ms 220868 KB Output is correct
26 Correct 125 ms 221016 KB Output is correct
27 Correct 131 ms 220872 KB Output is correct
28 Correct 124 ms 221672 KB Output is correct
29 Correct 128 ms 223416 KB Output is correct
30 Correct 118 ms 221472 KB Output is correct
31 Correct 124 ms 222248 KB Output is correct
32 Correct 122 ms 221652 KB Output is correct
33 Correct 138 ms 226240 KB Output is correct
34 Correct 142 ms 226216 KB Output is correct
35 Correct 147 ms 225220 KB Output is correct
36 Correct 121 ms 221380 KB Output is correct
37 Correct 168 ms 228676 KB Output is correct
38 Correct 158 ms 227900 KB Output is correct
39 Correct 171 ms 227888 KB Output is correct
40 Correct 159 ms 227908 KB Output is correct
41 Correct 180 ms 227884 KB Output is correct
42 Correct 123 ms 220996 KB Output is correct
43 Correct 128 ms 221016 KB Output is correct
44 Correct 128 ms 220956 KB Output is correct
45 Correct 264 ms 243396 KB Output is correct
46 Correct 275 ms 243484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 220624 KB Output is correct
2 Correct 117 ms 220612 KB Output is correct
3 Correct 124 ms 220572 KB Output is correct
4 Correct 120 ms 220612 KB Output is correct
5 Correct 118 ms 220608 KB Output is correct
6 Correct 119 ms 220612 KB Output is correct
7 Correct 118 ms 220600 KB Output is correct
8 Correct 119 ms 220620 KB Output is correct
9 Correct 120 ms 220652 KB Output is correct
10 Correct 119 ms 220612 KB Output is correct
11 Correct 147 ms 220828 KB Output is correct
12 Correct 118 ms 220612 KB Output is correct
13 Correct 118 ms 220616 KB Output is correct
14 Correct 128 ms 221080 KB Output is correct
15 Correct 118 ms 220856 KB Output is correct
16 Correct 122 ms 220740 KB Output is correct
17 Correct 120 ms 221264 KB Output is correct
18 Correct 121 ms 220952 KB Output is correct
19 Correct 118 ms 220756 KB Output is correct
20 Correct 118 ms 220712 KB Output is correct
21 Correct 121 ms 220716 KB Output is correct
22 Correct 118 ms 220892 KB Output is correct
23 Correct 122 ms 220816 KB Output is correct
24 Correct 131 ms 221092 KB Output is correct
25 Correct 122 ms 220868 KB Output is correct
26 Correct 119 ms 220948 KB Output is correct
27 Correct 124 ms 220964 KB Output is correct
28 Correct 126 ms 221664 KB Output is correct
29 Correct 127 ms 223516 KB Output is correct
30 Correct 123 ms 221376 KB Output is correct
31 Correct 123 ms 222276 KB Output is correct
32 Correct 129 ms 221692 KB Output is correct
33 Correct 138 ms 226260 KB Output is correct
34 Correct 138 ms 226244 KB Output is correct
35 Correct 148 ms 225236 KB Output is correct
36 Correct 129 ms 221756 KB Output is correct
37 Correct 168 ms 228608 KB Output is correct
38 Correct 161 ms 227868 KB Output is correct
39 Correct 167 ms 227908 KB Output is correct
40 Correct 166 ms 227976 KB Output is correct
41 Correct 167 ms 227908 KB Output is correct
42 Correct 146 ms 221004 KB Output is correct
43 Correct 132 ms 221152 KB Output is correct
44 Correct 124 ms 220932 KB Output is correct
45 Correct 300 ms 243400 KB Output is correct
46 Correct 269 ms 243396 KB Output is correct
47 Correct 335 ms 255204 KB Output is correct
48 Correct 156 ms 231492 KB Output is correct
49 Correct 141 ms 227240 KB Output is correct
50 Correct 142 ms 227504 KB Output is correct
51 Correct 196 ms 235248 KB Output is correct
52 Correct 209 ms 236688 KB Output is correct
53 Correct 146 ms 224940 KB Output is correct
54 Correct 129 ms 222032 KB Output is correct
55 Correct 129 ms 223180 KB Output is correct
56 Correct 130 ms 223172 KB Output is correct
57 Correct 210 ms 240920 KB Output is correct
58 Correct 131 ms 223844 KB Output is correct
59 Correct 139 ms 225260 KB Output is correct
60 Correct 144 ms 226960 KB Output is correct
61 Correct 141 ms 225752 KB Output is correct
62 Correct 205 ms 243924 KB Output is correct
63 Runtime error 223 ms 262148 KB Execution killed with signal 9
64 Halted 0 ms 0 KB -