답안 #400750

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
400750 2021-05-08T15:45:25 Z BERNARB01 Jakarta Skyscrapers (APIO15_skyscraper) C++17
0 / 100
1 ms 204 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<vector<pair<int, long long>>> g(n);
	for (int i = 0; i < n; i++) {
		int b, p;
		cin >> b >> p;
		for (int j = b + p, w = 1; j < n; j += p, w++) {
			g[b].emplace_back(j, w);
		}
		for (int j = b - p, w = 1; j >= 0; j -= p, w++) {
			g[b].emplace_back(j, w);
		}
	}
	priority_queue<pair<int, long long>, vector<pair<int, long long>>, less<pair<int, long long>>> s;
	const long long inf = 8e18;
	vector<long long> dist(n, inf);
	dist[0] = 0;
	s.emplace(0, 0);
	while (!s.empty()) {
		auto [u, exp] = s.top();
		s.pop();
		if (exp != dist[u]) {
			continue;
		}
		for (auto [v, w] : g[u]) {
			if (dist[v] > dist[u] + w) {
				dist[v] = dist[u] + w;
				s.emplace(v, dist[v]);
			}
		}
	}
	cout << (dist[1] == inf ? -1 : dist[1]) << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -