Submission #478946

# Submission time Handle Problem Language Result Execution time Memory
478946 2021-10-09T07:34:24 Z IvnF Jakarta Skyscrapers (APIO15_skyscraper) C++14
10 / 100
2 ms 1176 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ull unsigned long long
#define fi first
#define se second
#define ld long double
ll n, m, dist[30005];
vector<pair<ll, ll>>edge[30005];

struct struk{
	ll b, p;
}; struk arr[30005];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for(int i=1;i<=n;++i) dist[i]=4e18;
	for(int i=1;i<=m;++i){
		cin >> arr[i].b >> arr[i].p;
		arr[i].b++;
	}
	for(int i=1;i<=m;++i){
		for(int j=1;j<=m;++j){
			if(j == i) continue;
			if(abs(arr[j].b - arr[i].b) % arr[i].p == 0){
				edge[i].pb({j, abs(arr[j].b - arr[i].b) / arr[i].p});
			}
		}
	}
	priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>pq;
	pq.push({0, 1});
	dist[1]=0;
	while(!pq.empty()){
		ll gerak=pq.top().fi, idx=pq.top().se;
		pq.pop();
		for(auto x:edge[idx]){
			if(dist[x.fi] > gerak+x.se){
				dist[x.fi] = gerak+x.se;
				pq.push({dist[x.fi], x.fi});
			}
		}
	}
	cout << (dist[2] == 4e18 ? -1 : dist[2]) << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 1028 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1036 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Incorrect 2 ms 1100 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Incorrect 2 ms 1100 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1028 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 1032 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Incorrect 2 ms 1176 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 972 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 1 ms 972 KB Output is correct
10 Incorrect 2 ms 1100 KB Output isn't correct
11 Halted 0 ms 0 KB -