답안 #972098

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
972098 2024-04-30T05:13:18 Z Halym2007 Jakarta Skyscrapers (APIO15_skyscraper) C++17
0 / 100
2 ms 3416 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define sz size()
#define pii pair <int, int>
const int N = 3e4 + 5;

map <int, bool> m[N];
vector <pii> v[N];
vector <int> q[N];
int n, k, dis[N];

priority_queue <pii, vector <pii>, greater <pii>> p;


int main () {
//	freopen ("input.txt", "r", stdin);
	cin >> n >> k;
	for (int i = 1; i <= k; ++i) {
		int x, y;
		cin >> x >> y;
		if (m[x].find (y) == m[x].end()) {
			q[x].pb (y);
			m[x][y] = 1;
		}
	}
	for (int i = 0; i < n; ++i) {
		for (int j : q[i]) {
			int val = i + j;
			int bal = 1;
			while (val < n) {
				v[i].pb ({val, bal});
				if (m[val].find (j) != m[val].end()) {
					break;
				}
				bal++;
				val += j;
			}
			val = i - j;
			bal = 1;
			while (val >= 0) {
				v[i].pb ({val, bal});
				if (m[val].find (j) != m[val].end()) {
					break;
				}
				bal++;
				val -= j;
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		dis[i] = 1e9;
	}
	p.push ({0, 0});
	dis[0] = 0;
	while (!p.empty()) {
		int x = p.top().ss;
		p.pop();
		for (pii i : v[x]) {
			if (dis[i.ff] > dis[x] + i.ss) {
				dis[i.ff] = dis[x] + i.ss;
				p.push({dis[i.ff], i.ff});
			}
		}
	}
	if (dis[1] == 1e9) dis[1] = -1;
	cout << dis[1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3164 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Incorrect 1 ms 3164 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3160 KB Output is correct
2 Correct 1 ms 3160 KB Output is correct
3 Incorrect 1 ms 3416 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3164 KB Output is correct
2 Correct 2 ms 3164 KB Output is correct
3 Incorrect 1 ms 3164 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3164 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Incorrect 1 ms 3164 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3164 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Incorrect 2 ms 3164 KB Output isn't correct
4 Halted 0 ms 0 KB -