Submission #417783

#TimeUsernameProblemLanguageResultExecution timeMemory
417783DEQKJakarta Skyscrapers (APIO15_skyscraper)C++17
0 / 100
1 ms972 KiB
#include <bits/stdc++.h>

#define ll long long
using namespace std;
const int N = 3e4 + 10;
vector<vector<pair<int, int>>> g(N);
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	short n, m; cin >> n >> m;
	int f, s;
	for(short i = 0; i < m; i++) {
		short x, y; cin >> x >> y;
		if(i == 0) f = x;
		if(i == 1) s = x;
		if(y == 0) continue;
		for(short j = x + y; j < n; j += y) {
			g[x].push_back({j, (j - x) / y});
		}
		for(short j = x - y; j >= 0; j -= y) {
			g[x].push_back({j, (x - j) / y});
		}
	}
	priority_queue<pair<ll, short>, vector<pair<ll, short>>, greater<pair<ll, short>>> c;
	vector<ll> d(n, 1e10);
	d[f] = 0;
	c.push({0, f});
	while(!c.empty()) {
		ll w; short u; 
		tie(w, u) = c.top();
		c.pop();
		if(d[u] != w) continue;
		for(pair<ll, int> to : g[u]) {
			if(d[to.first] > d[u] + to.second) {
				d[to.first] = d[u] + to.second;
				c.push({d[to.first], to.first});
			}
		}
	}
	cout << (d[s] == 1e15 ? -1 : d[s]);
}

Compilation message (stderr)

skyscraper.cpp: In function 'int main()':
skyscraper.cpp:39:14: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   39 |  cout << (d[s] == 1e15 ? -1 : d[s]);
      |              ^
#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...