답안 #671633

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
671633 2022-12-13T11:51:38 Z Radin_Zahedi2 Jakarta Skyscrapers (APIO15_skyscraper) C++17
36 / 100
36 ms 16144 KB
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)x.size()
#define endl '\n'
const int mod = 1e9 + 7;
const int inf = 1e9 + 5;
const ll linf = 9e18 + 5;


int n, m;
const int N = 2e3 + 5;
int arr[N][2];

int w[N][N];
int dist[N];

void init() {
}

void input() {
	cin >> m >> n;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i][0] >> arr[i][1];
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (abs(arr[j][0] - arr[i][0]) % arr[i][1] == 0) {
				w[i][j] = abs(arr[j][0] - arr[i][0]) / arr[i][1];
			}
			else {
				w[i][j] = inf;
			}
		}
	}
}

void dijk() {
	set<pair<int, int>> dists;

	for (int i = 1; i <= n; i++) {
		dist[i] = inf;
		dists.insert(mp(dist[i], i));
	}

	dists.erase(mp(dist[1], 1));
	dist[1] = 0;
	dists.insert(mp(dist[1], 1));

	while (!dists.empty()) {
		int u = dists.begin()->se;
		dists.erase(dists.begin());

		for (int v = 1; v <= n; v++) {
			if (dist[v] > dist[u] + w[u][v]) {
				dists.erase(mp(dist[v], v));
				dist[v] = dist[u] + w[u][v];
				dists.insert(mp(dist[v], v));
			}
		}
	}
}

void solve() {
	dijk();

	if (dist[2] == inf) {
		cout << -1;
	}
	else {
		cout << dist[2];
	}
}

void output() {
}

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

	int number_of_testcases = 1;
	//cin >> number_of_testcases;
	while (number_of_testcases--) {
		init();

		input();

		solve();

		output();
	}

	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 224 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 2 ms 2516 KB Output is correct
11 Correct 30 ms 16108 KB Output is correct
12 Correct 29 ms 16060 KB Output is correct
13 Correct 28 ms 16112 KB Output is correct
14 Correct 29 ms 16140 KB Output is correct
15 Correct 28 ms 16080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 2516 KB Output is correct
11 Correct 29 ms 16084 KB Output is correct
12 Correct 28 ms 16116 KB Output is correct
13 Correct 28 ms 16088 KB Output is correct
14 Correct 28 ms 16108 KB Output is correct
15 Correct 29 ms 16060 KB Output is correct
16 Correct 7 ms 6468 KB Output is correct
17 Correct 24 ms 14360 KB Output is correct
18 Correct 9 ms 8148 KB Output is correct
19 Correct 3 ms 3668 KB Output is correct
20 Correct 33 ms 16064 KB Output is correct
21 Correct 12 ms 9488 KB Output is correct
22 Correct 5 ms 5204 KB Output is correct
23 Correct 8 ms 7764 KB Output is correct
24 Correct 26 ms 15180 KB Output is correct
25 Correct 28 ms 16092 KB Output is correct
26 Correct 29 ms 16124 KB Output is correct
27 Correct 29 ms 16076 KB Output is correct
28 Correct 30 ms 16112 KB Output is correct
29 Correct 6 ms 5500 KB Output is correct
30 Correct 1 ms 1108 KB Output is correct
31 Correct 4 ms 4052 KB Output is correct
32 Correct 3 ms 3156 KB Output is correct
33 Correct 29 ms 16076 KB Output is correct
34 Correct 29 ms 16120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 2516 KB Output is correct
11 Correct 29 ms 16068 KB Output is correct
12 Correct 29 ms 16144 KB Output is correct
13 Correct 28 ms 16084 KB Output is correct
14 Correct 29 ms 16084 KB Output is correct
15 Correct 29 ms 16108 KB Output is correct
16 Correct 7 ms 6492 KB Output is correct
17 Correct 24 ms 14304 KB Output is correct
18 Correct 9 ms 8148 KB Output is correct
19 Correct 4 ms 3668 KB Output is correct
20 Correct 33 ms 16084 KB Output is correct
21 Correct 11 ms 9556 KB Output is correct
22 Correct 5 ms 5204 KB Output is correct
23 Correct 9 ms 7748 KB Output is correct
24 Correct 27 ms 15200 KB Output is correct
25 Correct 29 ms 16084 KB Output is correct
26 Correct 29 ms 16124 KB Output is correct
27 Correct 29 ms 16076 KB Output is correct
28 Correct 28 ms 16076 KB Output is correct
29 Correct 6 ms 5456 KB Output is correct
30 Correct 1 ms 1108 KB Output is correct
31 Correct 4 ms 4052 KB Output is correct
32 Correct 3 ms 3156 KB Output is correct
33 Correct 29 ms 16120 KB Output is correct
34 Correct 29 ms 16060 KB Output is correct
35 Incorrect 6 ms 5972 KB Output isn't correct
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 3 ms 2516 KB Output is correct
11 Correct 29 ms 16072 KB Output is correct
12 Correct 28 ms 16084 KB Output is correct
13 Correct 29 ms 16060 KB Output is correct
14 Correct 35 ms 16020 KB Output is correct
15 Correct 29 ms 16068 KB Output is correct
16 Correct 8 ms 6484 KB Output is correct
17 Correct 27 ms 14344 KB Output is correct
18 Correct 10 ms 8040 KB Output is correct
19 Correct 5 ms 3668 KB Output is correct
20 Correct 34 ms 16084 KB Output is correct
21 Correct 12 ms 9584 KB Output is correct
22 Correct 5 ms 5204 KB Output is correct
23 Correct 9 ms 7764 KB Output is correct
24 Correct 27 ms 15144 KB Output is correct
25 Correct 29 ms 16084 KB Output is correct
26 Correct 29 ms 16016 KB Output is correct
27 Correct 36 ms 16064 KB Output is correct
28 Correct 30 ms 16140 KB Output is correct
29 Correct 7 ms 5460 KB Output is correct
30 Correct 1 ms 1108 KB Output is correct
31 Correct 4 ms 4052 KB Output is correct
32 Correct 3 ms 3180 KB Output is correct
33 Correct 30 ms 16084 KB Output is correct
34 Correct 31 ms 16116 KB Output is correct
35 Incorrect 7 ms 5900 KB Output isn't correct
36 Halted 0 ms 0 KB -