답안 #520012

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
520012 2022-01-28T06:04:49 Z Giantpizzahead Soccer (JOI17_soccer) C++17
35 / 100
997 ms 24848 KB
/*
Solution: 
Runtime: 
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define sz(x) ((int) x.size())
#define all(x) x.begin(), x.end()
#define debug if (true) cerr
using ll = long long;

const int MAXD = 505;
const ll INF = 1e18;

int H, W, N;
int si, sj, ei, ej;
ll A, B, C;
ll costP[MAXD][MAXD];

int ci[] = {1, 0, -1, 0}, cj[] = {0, 1, 0, -1};

inline bool inBounds(int i, int j) {
    return i >= 0 && i < H && j >= 0 && j < W;
}

// 0-3 = Being kicked, 4 = Player has the ball
ll bestC[MAXD][MAXD][5];
struct Loc {
    int i, j, k;
    ll c;
    bool operator<(const Loc& o) const {
        return c > o.c;
    }
};
priority_queue<Loc> pq;

void tryTrans(int i, int j, int k, ll c) {
    if (!inBounds(i, j) || bestC[i][j][k] <= c) return;
    bestC[i][j][k] = c;
    pq.push({i, j, k, c});
}

void bfs() {
    bestC[si][sj][4] = 0;
    pq.push({si, sj, 4, 0});
    while (!pq.empty()) {
        Loc l = pq.top(); pq.pop();
        int i = l.i, j = l.j, k = l.k;
        ll c = l.c;
        if (k == 4) {
            // Player has the ball
            rep(d, 0, 4) {
                tryTrans(i + ci[d], j + cj[d], 4, c + C);  // Move with the ball
                tryTrans(i, j, d, c + B);  // Kick the ball in a direction
            }
        } else {
            // Ball is being kicked
            // Continue moving the ball
            tryTrans(i + ci[k], j + cj[k], k, c + A);
            // Stop moving and have a player pick up the ball
            tryTrans(i, j, 4, c + costP[i][j]);
        }
    }
}

void solve() {
    cin >> H >> W;
    H++, W++;
    cin >> A >> B >> C;
    cin >> N;
    rep(i, 0, H) rep(j, 0, W) {
        costP[i][j] = INF;
        rep(k, 0, 5) bestC[i][j][k] = INF;
    }
    rep(k, 0, N) {
        int i, j; cin >> i >> j;
        if (k == 0) si = i, sj = j;
        else if (k == N-1) ei = i, ej = j;
        rep(d, 0, 4) {
            int ni = i, nj = j;
            ll currC = 0;
            while (inBounds(ni, nj)) {
                costP[ni][nj] = min(currC, costP[ni][nj]);
                ni += ci[d], nj += cj[d], currC += C;
            }
        }
    }
    bfs();
    ll ans = INF;
    rep(i, 0, H) rep(j, 0, W) rep(k, 0, 5) {
        ll cost = bestC[i][j][k] + C * (abs(ei-i) + abs(ej-j));
        ans = min(cost, ans);
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 5196 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 133 ms 12300 KB Output is correct
4 Correct 144 ms 12356 KB Output is correct
5 Correct 43 ms 6800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 290 ms 13836 KB Output is correct
2 Correct 245 ms 15416 KB Output is correct
3 Correct 174 ms 13028 KB Output is correct
4 Correct 213 ms 13964 KB Output is correct
5 Correct 257 ms 15292 KB Output is correct
6 Correct 271 ms 18484 KB Output is correct
7 Correct 369 ms 18436 KB Output is correct
8 Correct 290 ms 18392 KB Output is correct
9 Correct 382 ms 24848 KB Output is correct
10 Correct 45 ms 7492 KB Output is correct
11 Correct 385 ms 18480 KB Output is correct
12 Correct 274 ms 15416 KB Output is correct
13 Correct 218 ms 16112 KB Output is correct
14 Correct 385 ms 18440 KB Output is correct
15 Correct 284 ms 18436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 5196 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 133 ms 12300 KB Output is correct
4 Correct 144 ms 12356 KB Output is correct
5 Correct 43 ms 6800 KB Output is correct
6 Correct 290 ms 13836 KB Output is correct
7 Correct 245 ms 15416 KB Output is correct
8 Correct 174 ms 13028 KB Output is correct
9 Correct 213 ms 13964 KB Output is correct
10 Correct 257 ms 15292 KB Output is correct
11 Correct 271 ms 18484 KB Output is correct
12 Correct 369 ms 18436 KB Output is correct
13 Correct 290 ms 18392 KB Output is correct
14 Correct 382 ms 24848 KB Output is correct
15 Correct 45 ms 7492 KB Output is correct
16 Correct 385 ms 18480 KB Output is correct
17 Correct 274 ms 15416 KB Output is correct
18 Correct 218 ms 16112 KB Output is correct
19 Correct 385 ms 18440 KB Output is correct
20 Correct 284 ms 18436 KB Output is correct
21 Correct 49 ms 6696 KB Output is correct
22 Correct 279 ms 15404 KB Output is correct
23 Correct 306 ms 14160 KB Output is correct
24 Correct 516 ms 18396 KB Output is correct
25 Correct 424 ms 18452 KB Output is correct
26 Correct 403 ms 18584 KB Output is correct
27 Correct 583 ms 12968 KB Output is correct
28 Correct 743 ms 13188 KB Output is correct
29 Correct 893 ms 16120 KB Output is correct
30 Correct 729 ms 13068 KB Output is correct
31 Correct 371 ms 18484 KB Output is correct
32 Correct 997 ms 19116 KB Output is correct
33 Correct 305 ms 18464 KB Output is correct
34 Incorrect 419 ms 18396 KB Output isn't correct
35 Halted 0 ms 0 KB -