답안 #206235

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
206235 2020-03-02T19:02:04 Z stefdasca Soccer (JOI17_soccer) C++14
100 / 100
446 ms 21996 KB
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;

ll n, m, a, b, c, dist[502][502];

pair<int, int> plc[100002];

struct str
{
    int x, y, tip;
    ll cost;
};
struct cmp
{
    bool operator()(str a, str b)
    {
        return a.cost > b.cost;
    }
};
priority_queue<str, vector<str>, cmp> pq;

ll dp[502][502][5];
bool viz[502][502][5];
int ox[] = {-1, 0, 1, 0};
int oy[] = {0, 1, 0, -1};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m >> a >> b >> c;
    for(int i = 0; i <= n; ++i)
        for(int j = 0; j <= m; ++j)
        {
            for(int dir = 0; dir <= 4; ++dir)
                dp[i][j][dir] = (1LL<<60);
            dist[i][j] = (1<<20);
        }
    int cnt;
    cin >> cnt;
    queue<pair<int, int> >q;
    for(int i = 1; i <= cnt; ++i)
    {
        cin >> plc[i].fi >> plc[i].se;
        dist[plc[i].fi][plc[i].se] = 0;
        q.push({plc[i].fi, plc[i].se});
    }
    while(!q.empty())
    {
        pair<int, int> poz = q.front();
        q.pop();
        for(int i = 0; i <= 3; ++i)
        {
            int nxt_x = poz.fi + ox[i];
            int nxt_y = poz.se + oy[i];
            if(nxt_x < 0 || nxt_x == n+1 || nxt_y < 0 || nxt_y == m+1)
                continue;
            if(dist[nxt_x][nxt_y] == (1<<20))
            {
                dist[nxt_x][nxt_y] = dist[poz.fi][poz.se] + 1;
                q.push({nxt_x, nxt_y});
            }
        }
    }
    dp[plc[1].fi][plc[1].se][4] = 0;
    pq.push({plc[1].fi, plc[1].se, 4, 0});
    while(!pq.empty())
    {
        str state = pq.top();
        pq.pop();
        if(viz[state.x][state.y][state.tip])
            continue;
        viz[state.x][state.y][state.tip] = 1;
        if(state.tip == 4)
        {
            for(int i = 0; i < 4; ++i)
            {
                int nxt_x = state.x + ox[i];
                int nxt_y = state.y + oy[i];
                if(nxt_x < 0 || nxt_x == n+1 || nxt_y < 0 || nxt_y == m+1)
                    continue;
                if(dp[nxt_x][nxt_y][4] > dp[state.x][state.y][4] + c)
                {
                    dp[nxt_x][nxt_y][4] = dp[state.x][state.y][4] + c;
                    pq.push({nxt_x, nxt_y, 4, dp[nxt_x][nxt_y][4]});
                }
            }
            for(int i = 0; i < 4; ++i)
                if(dp[state.x][state.y][4] + b < dp[state.x][state.y][i])
                {
                    dp[state.x][state.y][i] = dp[state.x][state.y][4] + b;
                    pq.push({state.x, state.y, i, dp[state.x][state.y][i]});
                }
        }
        else
        {
            if(dp[state.x][state.y][state.tip] + c * dist[state.x][state.y] < dp[state.x][state.y][4])
            {
                dp[state.x][state.y][4] = dp[state.x][state.y][state.tip] + c * dist[state.x][state.y];
                pq.push({state.x, state.y, 4, dp[state.x][state.y][4]});
            }
            int nxt_x = state.x + ox[state.tip];
            int nxt_y = state.y + oy[state.tip];
            if(nxt_x < 0 || nxt_x == n+1 || nxt_y < 0 || nxt_y == m+1)
                continue;
            if(dp[state.x][state.y][state.tip] + a < dp[nxt_x][nxt_y][state.tip])
            {
                dp[nxt_x][nxt_y][state.tip] = dp[state.x][state.y][state.tip] + a;
                pq.push({nxt_x, nxt_y, state.tip, dp[nxt_x][nxt_y][state.tip]});
            }
        }
    }
    cout << dp[plc[cnt].fi][plc[cnt].se][4] << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 7672 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 289 ms 19684 KB Output is correct
4 Correct 311 ms 19688 KB Output is correct
5 Correct 53 ms 7672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 323 ms 19696 KB Output is correct
2 Correct 329 ms 19704 KB Output is correct
3 Correct 237 ms 17136 KB Output is correct
4 Correct 243 ms 19688 KB Output is correct
5 Correct 240 ms 19704 KB Output is correct
6 Correct 265 ms 19688 KB Output is correct
7 Correct 317 ms 19732 KB Output is correct
8 Correct 305 ms 19732 KB Output is correct
9 Correct 316 ms 19732 KB Output is correct
10 Correct 48 ms 8864 KB Output is correct
11 Correct 319 ms 19856 KB Output is correct
12 Correct 328 ms 19712 KB Output is correct
13 Correct 196 ms 17128 KB Output is correct
14 Correct 318 ms 19860 KB Output is correct
15 Correct 258 ms 19728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 7672 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 289 ms 19684 KB Output is correct
4 Correct 311 ms 19688 KB Output is correct
5 Correct 53 ms 7672 KB Output is correct
6 Correct 323 ms 19696 KB Output is correct
7 Correct 329 ms 19704 KB Output is correct
8 Correct 237 ms 17136 KB Output is correct
9 Correct 243 ms 19688 KB Output is correct
10 Correct 240 ms 19704 KB Output is correct
11 Correct 265 ms 19688 KB Output is correct
12 Correct 317 ms 19732 KB Output is correct
13 Correct 305 ms 19732 KB Output is correct
14 Correct 316 ms 19732 KB Output is correct
15 Correct 48 ms 8864 KB Output is correct
16 Correct 319 ms 19856 KB Output is correct
17 Correct 328 ms 19712 KB Output is correct
18 Correct 196 ms 17128 KB Output is correct
19 Correct 318 ms 19860 KB Output is correct
20 Correct 258 ms 19728 KB Output is correct
21 Correct 69 ms 7552 KB Output is correct
22 Correct 416 ms 19692 KB Output is correct
23 Correct 397 ms 15432 KB Output is correct
24 Correct 425 ms 16684 KB Output is correct
25 Correct 382 ms 19700 KB Output is correct
26 Correct 389 ms 20000 KB Output is correct
27 Correct 228 ms 15356 KB Output is correct
28 Correct 220 ms 15960 KB Output is correct
29 Correct 348 ms 18672 KB Output is correct
30 Correct 191 ms 15740 KB Output is correct
31 Correct 364 ms 19860 KB Output is correct
32 Correct 446 ms 21996 KB Output is correct
33 Correct 289 ms 19688 KB Output is correct
34 Correct 425 ms 19860 KB Output is correct
35 Correct 160 ms 15740 KB Output is correct