답안 #753996

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
753996 2023-06-06T13:00:40 Z pavement Soccer (JOI17_soccer) C++17
0 / 100
21 ms 3384 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//~ #define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
#define g4(a) get<4>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using db = double;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
using iiii = tuple<int, int, int, int>;
using iiiii = tuple<int, int, int, int, int>;
template<class key, class value = null_type, class cmp = less<key> >
using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

using lii = tuple<ll, int, int>;

int H, W, N, dr[] = {-1, 0, 0, 1}, dc[] = {0, -1, 1, 0}, dist[505][505], S[100005], T[100005];
ll A, B, C, ans[505][505];
bool hflip, vflip;
queue<iii> Q;

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> H >> W >> A >> B >> C >> N;
	H++;
	W++;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			dist[i][j] = (int)1e9;
			ans[i][j] = (ll)1e16;
		}
	}
	for (int i = 1; i <= N; i++) {
		cin >> S[i] >> T[i];
		S[i]++;
		T[i]++;
	}
	if (S[1] > S[N]) hflip = 1;
	if (T[1] > T[N]) vflip = 1;
	for (int i = 1; i <= N; i++) {
		if (hflip) S[i] = H - S[i] + 1;
		if (vflip) T[i] = W - T[i] + 1;
		if (dist[S[i]][T[i]]) {
			dist[S[i]][T[i]] = 0;
			Q.emplace(0, S[i], T[i]);
		}
	}
	while (!Q.empty()) {
		auto [d, r, c] = Q.front();
		Q.pop();
		if (d != dist[r][c]) continue;
		for (int k = 0; k < 4; k++) {
			int nr = r + dr[k], nc = c + dc[k];
			if (1 <= nr && nr <= H && 1 <= nc && nc <= W && dist[nr][nc] > d + 1) {
				dist[nr][nc] = d + 1;
				Q.emplace(d + 1, nr, nc);
			}
		}
	}
	ans[S[1]][T[1]] = 0;
	for (int i = S[1]; i <= S[N]; i++) {
		for (int j = T[1]; j <= T[N]; j++) {
			for (int k = S[1]; k < i; k++) {
				// (k, j)
				ans[i][j] = min(ans[i][j], ans[k][j] + min(llabs(k - i) * C, llabs(k - i) * A + B) + C * dist[i][j]);
			}
			for (int k = T[1]; k < j; k++) {
				// (i, k)
				ans[i][j] = min(ans[i][j], ans[i][k] + min(llabs(k - j) * C, llabs(k - j) * A + B) + C * dist[i][j]);
			}
		}
	}
	cout << ans[S[N]][T[N]] << '\n';
}

Compilation message

soccer.cpp:35:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   35 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 2132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 3384 KB Output is correct
2 Incorrect 21 ms 3276 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 2132 KB Output isn't correct
2 Halted 0 ms 0 KB -