Submission #402991

# Submission time Handle Problem Language Result Execution time Memory
402991 2021-05-12T16:01:34 Z yoavL Jakarta Skyscrapers (APIO15_skyscraper) C++14
36 / 100
1000 ms 236256 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

#define upmax(a, b) a = max(a, b);
#define upmin(a, b) a = min(a, b);
#define pr(x) cout << x << endl;
#define wpr(x) cout << #x << ": " << x << endl;
#define rep(i, s, e) for(ll i = s; i < e; i++)
#define rep(i, e) for(ll i = 0; i < e; i++)

using namespace std;

using ll = int;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pll = pair<ll, ll>;

const ll inf = 1e9;

ll n, m;
vvll d, have; // [place][sky ind]
vll s, p;


void bfs()
{
	deque<pll> q; // {place, sky ind}
	q.push_front({ s[0], 0 });
	d[s[0]][0] = 0;

	while (!q.empty()) {
		ll b = q.front().first;
		ll ind = q.front().second;
		//wpr(b);
		//wpr(ind);
		//cout << "dist: " << d[b][ind] << endl;
		q.pop_front();
		rep(i, have[b].size()) {
			if (d[b][have[b][i]] != inf) continue;
			d[b][have[b][i]] = d[b][ind];
			q.push_front({ b, have[b][i] });
		}
		have[b].clear();

		ll jump = p[ind];
		if (b - jump >= 0 && d[b-jump][ind] == inf) {
			d[b - jump][ind] = d[b][ind] + 1;
			q.push_back({ b - jump, ind });
		}


		
		if (b + jump < n && d[b + jump][ind] == inf) {
			d[b + jump][ind] = d[b][ind] + 1;
			q.push_back({ b + jump, ind });
		}
	}

}

int main()
{
	cin >> n >> m;
	s.resize(m);
	p.resize(m);
	have.resize(n);
	rep(i, m) {
		cin >> s[i] >> p[i];
		have[s[i]].push_back(i);
	}

	d.resize(n, vll(m, inf));
	bfs();
	ll ans = d[s[1]][1];
	if (ans == inf) ans = -1;
	pr(ans);
}

/*


*/

Compilation message

skyscraper.cpp:11: warning: "rep" redefined
   11 | #define rep(i, e) for(ll i = 0; i < e; i++)
      | 
skyscraper.cpp:10: note: this is the location of the previous definition
   10 | #define rep(i, s, e) for(ll i = s; i < e; i++)
      | 
skyscraper.cpp: In function 'void bfs()':
skyscraper.cpp:11:35: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 | #define rep(i, e) for(ll i = 0; i < e; i++)
......
   43 |   rep(i, have[b].size()) {
      |       ~~~~~~~~~~~~~~~~~            
skyscraper.cpp:43:3: note: in expansion of macro 'rep'
   43 |   rep(i, have[b].size()) {
      |   ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 232 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 1100 KB Output is correct
12 Correct 6 ms 1084 KB Output is correct
13 Correct 7 ms 1100 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 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 3 ms 1100 KB Output is correct
12 Correct 7 ms 1140 KB Output is correct
13 Correct 7 ms 1100 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 5452 KB Output is correct
18 Correct 4 ms 7116 KB Output is correct
19 Correct 3 ms 4684 KB Output is correct
20 Correct 208 ms 16152 KB Output is correct
21 Correct 2 ms 2124 KB Output is correct
22 Correct 4 ms 5452 KB Output is correct
23 Correct 5 ms 6348 KB Output is correct
24 Correct 10 ms 14412 KB Output is correct
25 Correct 10 ms 16076 KB Output is correct
26 Correct 82 ms 16072 KB Output is correct
27 Correct 80 ms 16112 KB Output is correct
28 Correct 11 ms 16076 KB Output is correct
29 Correct 7 ms 6256 KB Output is correct
30 Correct 2 ms 1740 KB Output is correct
31 Correct 5 ms 5000 KB Output is correct
32 Correct 4 ms 4172 KB Output is correct
33 Correct 19 ms 16120 KB Output is correct
34 Correct 17 ms 16124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 1100 KB Output is correct
12 Correct 6 ms 1100 KB Output is correct
13 Correct 6 ms 1140 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 5484 KB Output is correct
18 Correct 5 ms 7116 KB Output is correct
19 Correct 4 ms 4684 KB Output is correct
20 Correct 192 ms 16152 KB Output is correct
21 Correct 3 ms 2124 KB Output is correct
22 Correct 4 ms 5324 KB Output is correct
23 Correct 4 ms 6348 KB Output is correct
24 Correct 9 ms 14412 KB Output is correct
25 Correct 10 ms 16068 KB Output is correct
26 Correct 83 ms 16112 KB Output is correct
27 Correct 81 ms 16076 KB Output is correct
28 Correct 12 ms 16076 KB Output is correct
29 Correct 8 ms 6220 KB Output is correct
30 Correct 2 ms 1836 KB Output is correct
31 Correct 5 ms 4940 KB Output is correct
32 Correct 4 ms 4172 KB Output is correct
33 Correct 18 ms 16116 KB Output is correct
34 Correct 18 ms 16120 KB Output is correct
35 Correct 98 ms 145600 KB Output is correct
36 Correct 14 ms 20684 KB Output is correct
37 Correct 124 ms 148096 KB Output is correct
38 Correct 178 ms 235760 KB Output is correct
39 Correct 153 ms 236100 KB Output is correct
40 Correct 153 ms 236192 KB Output is correct
41 Correct 155 ms 236080 KB Output is correct
42 Execution timed out 1106 ms 236256 KB Time limit exceeded
43 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 3 ms 1100 KB Output is correct
12 Correct 6 ms 1100 KB Output is correct
13 Correct 6 ms 1136 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 5452 KB Output is correct
18 Correct 6 ms 7116 KB Output is correct
19 Correct 3 ms 4684 KB Output is correct
20 Correct 208 ms 16156 KB Output is correct
21 Correct 2 ms 2124 KB Output is correct
22 Correct 4 ms 5324 KB Output is correct
23 Correct 5 ms 6348 KB Output is correct
24 Correct 9 ms 14412 KB Output is correct
25 Correct 9 ms 16076 KB Output is correct
26 Correct 84 ms 16104 KB Output is correct
27 Correct 80 ms 16104 KB Output is correct
28 Correct 12 ms 16076 KB Output is correct
29 Correct 6 ms 6260 KB Output is correct
30 Correct 2 ms 1740 KB Output is correct
31 Correct 5 ms 4940 KB Output is correct
32 Correct 4 ms 4172 KB Output is correct
33 Correct 18 ms 16060 KB Output is correct
34 Correct 17 ms 16120 KB Output is correct
35 Correct 98 ms 145620 KB Output is correct
36 Correct 17 ms 20684 KB Output is correct
37 Correct 125 ms 148040 KB Output is correct
38 Correct 150 ms 235756 KB Output is correct
39 Correct 155 ms 236124 KB Output is correct
40 Correct 175 ms 236084 KB Output is correct
41 Correct 147 ms 236072 KB Output is correct
42 Execution timed out 1099 ms 236252 KB Time limit exceeded
43 Halted 0 ms 0 KB -