Submission #676879

# Submission time Handle Problem Language Result Execution time Memory
676879 2023-01-01T12:56:04 Z Arnch Jakarta Skyscrapers (APIO15_skyscraper) C++17
100 / 100
811 ms 26700 KB
// oooo
/*
 har chi delet mikhad bebar ~
 gitar o ba khodet nabar! ~
 ;Amoo_Hasan;
*/

/*
	link:	
*/

#include<iostream>
#include<vector>
#include<set>
#include<queue>
#pragma GCC optimize("O3,no-stack-protector,unroll-loops")
#pragma GCC target("avx2,fma")

using namespace std;

typedef long long ll;
typedef long double ld;

#define Sz(x) int((x).size())
#define All(x) (x).begin(), (x).end()
#define wtf(x) cout<<#x <<" : " <<x <<endl
#define mak make_pair

//constexpr int PRI = 1000696969;
constexpr int INF = 1e9, N = 1e6 + 10, MOD = 1e9 + 7;

int b[N], x[N];
int d[N];
vector<int> vc[N];

int main() {
	ios :: sync_with_stdio(0), cin.tie(0); cout.tie(0);

	int n, m; cin >>n >>m;
	for(int i = 0; i < m; i++) {
		cin >>b[i] >>x[i];
		vc[b[i]].push_back(i);
	}
	
	for(int i = 0; i < n; i++) d[i] = INF;

	d[b[0]] = 0;
	priority_queue<pair<int, int> > st;
	st.push({0, b[0]});

	while(!st.empty()) {
		int q = -st.top().first, p = st.top().second;
		st.pop();
		if(d[p] != q) continue;

		if(p == b[1]) {
			return cout<<d[p], 0;
		}
		
		for(auto j : vc[p]) {
			for(int cnt = 1; p + cnt * x[j] < n; cnt++) {
				int pq = p + cnt * x[j];
				if(d[p] + cnt < d[pq]) {
					d[pq] = d[p] + cnt;
					st.push({-d[pq], pq});
				}
			}
			for(int cnt = 1; p - cnt * x[j] >= 0; cnt++) {
				int pq = p - cnt * x[j];
				if(d[p] + cnt < d[pq]) {
					d[pq] = d[p] + cnt;
					st.push({-d[pq], pq});
				}
			}
		}
	}

	cout<<-1;
	
	return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 12 ms 23764 KB Output is correct
2 Correct 13 ms 23708 KB Output is correct
3 Correct 12 ms 23760 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 12 ms 23764 KB Output is correct
7 Correct 12 ms 23780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23748 KB Output is correct
2 Correct 12 ms 23828 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 11 ms 23764 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 12 ms 23764 KB Output is correct
7 Correct 14 ms 23764 KB Output is correct
8 Correct 12 ms 23764 KB Output is correct
9 Correct 13 ms 23736 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 14 ms 23844 KB Output is correct
12 Correct 14 ms 23764 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 14 ms 23848 KB Output is correct
15 Correct 13 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23712 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 12 ms 23824 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 11 ms 23764 KB Output is correct
7 Correct 12 ms 23756 KB Output is correct
8 Correct 12 ms 23764 KB Output is correct
9 Correct 11 ms 23768 KB Output is correct
10 Correct 12 ms 23728 KB Output is correct
11 Correct 12 ms 23764 KB Output is correct
12 Correct 12 ms 23756 KB Output is correct
13 Correct 12 ms 23736 KB Output is correct
14 Correct 13 ms 23864 KB Output is correct
15 Correct 13 ms 23764 KB Output is correct
16 Correct 12 ms 23764 KB Output is correct
17 Correct 14 ms 23856 KB Output is correct
18 Correct 12 ms 23764 KB Output is correct
19 Correct 12 ms 23772 KB Output is correct
20 Correct 17 ms 23932 KB Output is correct
21 Correct 12 ms 23764 KB Output is correct
22 Correct 12 ms 23860 KB Output is correct
23 Correct 12 ms 23764 KB Output is correct
24 Correct 12 ms 23872 KB Output is correct
25 Correct 12 ms 23892 KB Output is correct
26 Correct 13 ms 23764 KB Output is correct
27 Correct 14 ms 23836 KB Output is correct
28 Correct 12 ms 23892 KB Output is correct
29 Correct 13 ms 23864 KB Output is correct
30 Correct 13 ms 23948 KB Output is correct
31 Correct 13 ms 23868 KB Output is correct
32 Correct 14 ms 24020 KB Output is correct
33 Correct 13 ms 23956 KB Output is correct
34 Correct 13 ms 23960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23812 KB Output is correct
2 Correct 12 ms 23828 KB Output is correct
3 Correct 12 ms 23748 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 12 ms 23764 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 12 ms 23704 KB Output is correct
9 Correct 12 ms 23764 KB Output is correct
10 Correct 12 ms 23764 KB Output is correct
11 Correct 16 ms 23864 KB Output is correct
12 Correct 13 ms 23764 KB Output is correct
13 Correct 12 ms 23764 KB Output is correct
14 Correct 12 ms 23868 KB Output is correct
15 Correct 12 ms 23764 KB Output is correct
16 Correct 12 ms 23764 KB Output is correct
17 Correct 12 ms 23824 KB Output is correct
18 Correct 13 ms 23812 KB Output is correct
19 Correct 14 ms 23736 KB Output is correct
20 Correct 19 ms 23856 KB Output is correct
21 Correct 12 ms 23764 KB Output is correct
22 Correct 12 ms 23864 KB Output is correct
23 Correct 13 ms 23860 KB Output is correct
24 Correct 13 ms 23876 KB Output is correct
25 Correct 13 ms 23892 KB Output is correct
26 Correct 13 ms 23832 KB Output is correct
27 Correct 14 ms 23936 KB Output is correct
28 Correct 12 ms 23892 KB Output is correct
29 Correct 13 ms 23892 KB Output is correct
30 Correct 12 ms 23892 KB Output is correct
31 Correct 13 ms 23860 KB Output is correct
32 Correct 13 ms 23892 KB Output is correct
33 Correct 14 ms 23956 KB Output is correct
34 Correct 13 ms 24020 KB Output is correct
35 Correct 17 ms 24276 KB Output is correct
36 Correct 13 ms 23816 KB Output is correct
37 Correct 17 ms 24276 KB Output is correct
38 Correct 19 ms 24368 KB Output is correct
39 Correct 17 ms 24308 KB Output is correct
40 Correct 17 ms 24404 KB Output is correct
41 Correct 18 ms 24296 KB Output is correct
42 Correct 18 ms 24288 KB Output is correct
43 Correct 16 ms 24264 KB Output is correct
44 Correct 80 ms 24276 KB Output is correct
45 Correct 18 ms 24276 KB Output is correct
46 Correct 18 ms 24276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23752 KB Output is correct
2 Correct 12 ms 23780 KB Output is correct
3 Correct 14 ms 23716 KB Output is correct
4 Correct 12 ms 23752 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 12 ms 23764 KB Output is correct
7 Correct 13 ms 23764 KB Output is correct
8 Correct 13 ms 23764 KB Output is correct
9 Correct 13 ms 23764 KB Output is correct
10 Correct 12 ms 23780 KB Output is correct
11 Correct 12 ms 23776 KB Output is correct
12 Correct 12 ms 23808 KB Output is correct
13 Correct 13 ms 23856 KB Output is correct
14 Correct 13 ms 23764 KB Output is correct
15 Correct 13 ms 23764 KB Output is correct
16 Correct 13 ms 23764 KB Output is correct
17 Correct 13 ms 23852 KB Output is correct
18 Correct 12 ms 23764 KB Output is correct
19 Correct 12 ms 23856 KB Output is correct
20 Correct 17 ms 23828 KB Output is correct
21 Correct 12 ms 23764 KB Output is correct
22 Correct 12 ms 23764 KB Output is correct
23 Correct 12 ms 23840 KB Output is correct
24 Correct 14 ms 23892 KB Output is correct
25 Correct 13 ms 23860 KB Output is correct
26 Correct 16 ms 23764 KB Output is correct
27 Correct 13 ms 23764 KB Output is correct
28 Correct 13 ms 23792 KB Output is correct
29 Correct 13 ms 23976 KB Output is correct
30 Correct 13 ms 23820 KB Output is correct
31 Correct 13 ms 23948 KB Output is correct
32 Correct 13 ms 23892 KB Output is correct
33 Correct 16 ms 23892 KB Output is correct
34 Correct 14 ms 24020 KB Output is correct
35 Correct 17 ms 24276 KB Output is correct
36 Correct 13 ms 23892 KB Output is correct
37 Correct 17 ms 24208 KB Output is correct
38 Correct 18 ms 24404 KB Output is correct
39 Correct 17 ms 24276 KB Output is correct
40 Correct 19 ms 24412 KB Output is correct
41 Correct 24 ms 24404 KB Output is correct
42 Correct 16 ms 24248 KB Output is correct
43 Correct 19 ms 24224 KB Output is correct
44 Correct 68 ms 24276 KB Output is correct
45 Correct 18 ms 24352 KB Output is correct
46 Correct 17 ms 24376 KB Output is correct
47 Correct 19 ms 25040 KB Output is correct
48 Correct 18 ms 24544 KB Output is correct
49 Correct 17 ms 24516 KB Output is correct
50 Correct 16 ms 24404 KB Output is correct
51 Correct 27 ms 25932 KB Output is correct
52 Correct 28 ms 25424 KB Output is correct
53 Correct 24 ms 24972 KB Output is correct
54 Correct 14 ms 24148 KB Output is correct
55 Correct 14 ms 24064 KB Output is correct
56 Correct 811 ms 25432 KB Output is correct
57 Correct 15 ms 25148 KB Output is correct
58 Correct 803 ms 24540 KB Output is correct
59 Correct 17 ms 24772 KB Output is correct
60 Correct 20 ms 24724 KB Output is correct
61 Correct 20 ms 24720 KB Output is correct
62 Correct 21 ms 25412 KB Output is correct
63 Correct 31 ms 25736 KB Output is correct
64 Correct 32 ms 25800 KB Output is correct
65 Correct 35 ms 25744 KB Output is correct
66 Correct 41 ms 26696 KB Output is correct
67 Correct 42 ms 26700 KB Output is correct