답안 #927022

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
927022 2024-02-14T06:55:56 Z Gromp15 Soccer (JOI17_soccer) C++17
35 / 100
1923 ms 262144 KB
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define db double
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rint(l, r) uniform_int_distribution<int>(l, r)(rng)
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
void test_case() {
	int h, w, a, b, c;
	cin >> h >> w >> a >> b >> c;
	int n; cin >> n;
	vector<ar<int, 2>> p(n);
	for (auto &x : p) cin >> x[0] >> x[1];
	// dp[x][y] = min cost to have a player at (x, y) possessing the ball
	// after a player gets the ball and moves and kicks the ball, they will not move again
	const int dx[]{0, 1, -1, 0}, dy[]{1, 0, 0, -1};
	auto in = [&](int x, int y) {
		return x >= 0 && y >= 0 && x <= h && y <= w;
	};
	vector<vector<int>> dp2(h+1, vector<int>(w+1, 1e9));
	{
		queue<ar<int, 2>> q;
		for (int i = 0; i < n; i++) {
			auto [x, y] = p[i];
			dp2[x][y] = 0;
			q.push({x, y});
		}
		while (q.size()) {
			auto [x, y] = q.front(); q.pop();
			for (int d = 0; d < 4; d++) {
				int nx = x + dx[d], ny = y + dy[d];
				if (!in(nx, ny)) continue;
				if (ckmin(dp2[nx][ny], dp2[x][y] + 1)) {
					q.push({nx, ny});
				}
			}
		}
	}
	vector<vector<ll>> dp(h+1, vector<ll>(w+1, 1e18));
	dp[p[0][0]][p[0][1]] = 0;
	priority_queue<ar<ll, 3>, vector<ar<ll, 3>>, greater<ar<ll, 3>>> q;
	q.push({0, p[0][0], p[0][1]});
	while (q.size()) {
		auto [weight, x, y] = q.top(); q.pop();
		if (weight != dp[x][y]) continue;
		// spread by walking
		for (int d = 0; d < 4; d++) {
			int nx = x + dx[d], ny = y + dy[d];
			if (in(nx, ny) && ckmin(dp[nx][ny], dp[x][y] + c)) {
				q.push({dp[nx][ny], nx, ny});
			}
		}
		// spread by kicking and having someone pick it up
		for (int d = 0; d < 4; d++) {
			for (int use = 1; use <= max(h, w); use++) {
				int nx = x + dx[d] * use, ny = y + dy[d] * use;
				if (!in(nx, ny)) break;
				if (ckmin(dp[nx][ny], dp[x][y] + (ll)dp2[nx][ny] * c + (ll)use * a + b)) {
					q.push({dp[nx][ny], nx, ny});
				}
			}
		}
	}
	cout << dp[p[n-1][0]][p[n-1][1]] << '\n';



}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
//    cin >> t;
    while (t--) test_case();
}

# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 2772 KB Output is correct
2 Correct 2 ms 800 KB Output is correct
3 Correct 1108 ms 10700 KB Output is correct
4 Correct 1923 ms 53420 KB Output is correct
5 Correct 229 ms 5324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1155 ms 11732 KB Output is correct
2 Correct 1185 ms 10440 KB Output is correct
3 Correct 745 ms 9100 KB Output is correct
4 Correct 1004 ms 11464 KB Output is correct
5 Correct 864 ms 9580 KB Output is correct
6 Correct 1006 ms 9836 KB Output is correct
7 Correct 1040 ms 10960 KB Output is correct
8 Correct 1044 ms 9936 KB Output is correct
9 Correct 1195 ms 9936 KB Output is correct
10 Correct 98 ms 2516 KB Output is correct
11 Correct 1077 ms 10956 KB Output is correct
12 Correct 1076 ms 10948 KB Output is correct
13 Correct 672 ms 9928 KB Output is correct
14 Correct 1123 ms 10252 KB Output is correct
15 Correct 840 ms 9420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 133 ms 2772 KB Output is correct
2 Correct 2 ms 800 KB Output is correct
3 Correct 1108 ms 10700 KB Output is correct
4 Correct 1923 ms 53420 KB Output is correct
5 Correct 229 ms 5324 KB Output is correct
6 Correct 1155 ms 11732 KB Output is correct
7 Correct 1185 ms 10440 KB Output is correct
8 Correct 745 ms 9100 KB Output is correct
9 Correct 1004 ms 11464 KB Output is correct
10 Correct 864 ms 9580 KB Output is correct
11 Correct 1006 ms 9836 KB Output is correct
12 Correct 1040 ms 10960 KB Output is correct
13 Correct 1044 ms 9936 KB Output is correct
14 Correct 1195 ms 9936 KB Output is correct
15 Correct 98 ms 2516 KB Output is correct
16 Correct 1077 ms 10956 KB Output is correct
17 Correct 1076 ms 10948 KB Output is correct
18 Correct 672 ms 9928 KB Output is correct
19 Correct 1123 ms 10252 KB Output is correct
20 Correct 840 ms 9420 KB Output is correct
21 Runtime error 404 ms 262144 KB Execution killed with signal 9
22 Halted 0 ms 0 KB -