답안 #991934

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
991934 2024-06-03T12:23:03 Z horezushol Soccer (JOI17_soccer) C++14
35 / 100
45 ms 16732 KB
#include<bits/stdc++.h>
#define debug(x) cout << "\033[36m"<< __LINE__ << ":\033[39m "  << (#x) << " = " << (x) << '\n'

#define F first
#define S second

const char nl = '\n';

using namespace std;
using ll = long long;

const ll N = 2000;
ll h, w, A, B, C, n;
vector<pair<ll, ll>> vp(N);

vector<pair<ll, ll>> g[N];
vector<ll> dist(N, LLONG_MAX);

 
ll go(ll x, ll y, ll X, ll Y) {
	return abs(x - X) + abs(y - Y);
}
 
ll shoot(ll x, ll y, ll X, ll Y) {
	ll res1 = abs(x - X)*C;
	ll res2 = abs(y - Y)*C;
	res1 += A*go(X, y, X, Y) + B;
	res2 += A*go(x, Y, X, Y) + B;
	return min(res1, res2);
}


void dij(ll x) {
	set<pair<ll, ll>> q;
	q.insert({0, x});
	dist[x] = 0;
	while (!q.empty()) {
		ll to = q.begin() -> S;
		q.erase(q.begin());
		for (auto el : g[to]) {
			ll L = el.F, R = el.S;
			if (dist[L] > dist[to] + R) {
				q.erase({dist[L], L});
				dist[L] = dist[to] + R;
				q.insert({dist[L], L});
			}
		}
	}
}

void solve() {
	cin >> h >> w >> A >> B >> C >> n;
	for (ll i = 1; i <= n; i ++) {
		cin >> vp[i].F >> vp[i].S;
	}
	for (ll i = 1; i <= n; i ++) {
		for (ll j = i+1; j <= n; j ++) {
			ll mn = shoot(vp[i].F, vp[i].S, vp[j].F, vp[j].S);
			mn = min(mn, go(vp[i].F, vp[i].S, vp[j].F, vp[j].S) * C);
			g[i].push_back({j, mn});
			g[j].push_back({i, mn});
		}
	}
	dij(1);
	cout << dist[n];
	// for (ll i = 1; i <= n; i ++) {
	// 	cout << i << ": ";
	// 	for (auto j : g[i]) {
	// 		cout << "[" << j.first << ", " << j.second << "] ";
	// 	}
	// 	cout << nl;
	// }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll tst = 1;
	// cin >> tst;
	while (tst --) {
		solve();
		cout << nl;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 2 ms 1372 KB Output is correct
6 Correct 45 ms 16724 KB Output is correct
7 Correct 20 ms 16732 KB Output is correct
8 Correct 21 ms 16732 KB Output is correct
9 Correct 24 ms 16732 KB Output is correct
10 Correct 20 ms 16732 KB Output is correct
11 Correct 23 ms 16732 KB Output is correct
12 Correct 1 ms 1116 KB Output is correct
13 Correct 41 ms 16732 KB Output is correct
14 Correct 19 ms 16732 KB Output is correct
15 Correct 20 ms 16732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 1372 KB Output is correct
11 Correct 45 ms 16724 KB Output is correct
12 Correct 20 ms 16732 KB Output is correct
13 Correct 21 ms 16732 KB Output is correct
14 Correct 24 ms 16732 KB Output is correct
15 Correct 20 ms 16732 KB Output is correct
16 Correct 23 ms 16732 KB Output is correct
17 Correct 1 ms 1116 KB Output is correct
18 Correct 41 ms 16732 KB Output is correct
19 Correct 19 ms 16732 KB Output is correct
20 Correct 20 ms 16732 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Incorrect 1 ms 604 KB Output isn't correct
23 Halted 0 ms 0 KB -