제출 #519725

#제출 시각아이디문제언어결과실행 시간메모리
519725naalJakarta Skyscrapers (APIO15_skyscraper)C++14
57 / 100
107 ms41036 KiB
// https://oj.uz/problem/view/APIO15_skyscraper
#include <bits/stdc++.h>
using namespace std;
 
#define Fname ((string) "io")
#define int long long
#define ii pair <int, int>
#define iii pair <int, ii>
#define fi first
#define se second
#define endl '\n'
const int INF = 1e16;
const int N = 3e3 + 5;
 
int n, m, d[N][N], goal;
vector <int> a[N];
priority_queue <iii, vector <iii>, greater <iii>> pq;
 
int find(int u) {
	for (int i = 1; i <= n; i++)
		for (int j = 0; j <= n; j++)
			d[i][j] = INF;
	pq.push({0, {u, 0}});
	d[u][0] = 0;
	while (pq.size()) {
		u = pq.top().se.fi;
		int step = pq.top().se.se, total = pq.top().fi;
		pq.pop();
		if (total != d[u][step])
			continue;
		if (u == goal)
			return total;
		a[u].push_back(step);
		for (int &step : a[u]) {
			d[u][step] = min(d[u][step], total);
			if (u + step <= n && d[u + step][step] > d[u][step] + 1) {
				d[u + step][step] = d[u][step] + 1;
				pq.push({d[u][step] + 1, {u + step, step}});
			}
			if (u - step > 0 && d[u - step][step] > d[u][step] + 1) {
				d[u - step][step] = d[u][step] + 1;
				pq.push({d[u][step] + 1, {u - step, step}});
			}		
		}
		a[u].pop_back();
	}
	return -1;
}
 
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef lan_ngu
		freopen((Fname + ".inp").c_str(), "r", stdin);
		freopen((Fname + ".out").c_str(), "w", stdout);
	#endif
 
	// int _nt; cin >> _nt;
	int _nt = 1;
	while (_nt--) {
		cin >> n >> m;
		int init;
		for (int i = 1; i <= m; i++) {
			int b, p; cin >> b >> p;
			b++;
			a[b].push_back(p);
			if (i == 1)
				init = b;
			else if (i == 2)
				goal = b;
		}	
		cout << find(init);
	}
 
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:72:20: warning: 'init' may be used uninitialized in this function [-Wmaybe-uninitialized]
   72 |   cout << find(init);
      |                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...