답안 #1052004

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1052004 2024-08-10T11:01:20 Z SamAnd Soccer (JOI17_soccer) C++17
100 / 100
405 ms 31456 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 503;
const int xx[4] = {0, 1, 0, -1};
const int yy[4] = {1, 0, -1, 0};

int n, m;
int A, B, C;
int k;
int x[N * N], y[N * N];
bool cc[N][N];
int dd[N][N];

struct ban
{
    int x, y, z;
    ll d;
    ban(){}
    ban(int x, int y, int z, ll d)
    {
        this->x = x;
        this->y = y;
        this->z = z;
        this->d = d;
    }
};
bool operator<(const ban& a, const ban& b)
{
    return a.d > b.d;
}

bool c[N][N][4 + 1];

void solv()
{
    cin >> n >> m;
    cin >> A >> B >> C;
    cin >> k;
    queue<pair<int, int> > qq;
    for (int i = 1; i <= k; ++i)
    {
        cin >> x[i] >> y[i];
        cc[x[i]][y[i]] = true;
        dd[x[i]][y[i]] = 0;
        qq.push(m_p(x[i], y[i]));
    }

    while (!qq.empty())
    {
        int x = qq.front().fi;
        int y = qq.front().se;
        qq.pop();
        for (int i = 0; i < 4; ++i)
        {
            int hx = x + xx[i];
            int hy = y + yy[i];
            if (0 <= hx && hx <= n && 0 <= hy && hy <= m && !cc[hx][hy])
            {
                cc[hx][hy] = true;
                dd[hx][hy] = dd[x][y] + 1;
                qq.push(m_p(hx, hy));
            }
        }
    }

    priority_queue<ban> q;
    q.push(ban(x[1], y[1], 4, 0));
    while (!q.empty())
    {
        ban t = q.top();
        q.pop();
        if (c[t.x][t.y][t.z])
            continue;
        c[t.x][t.y][t.z] = true;
        if (t.x == x[k] && t.y == y[k])
        {
            cout << t.d << "\n";
            return;
        }
        q.push(ban(t.x, t.y, 4, t.d + dd[t.x][t.y] * 1LL * C));

        if (t.z < 4)
        {
            ban h = t;
            h.x += xx[t.z];
            h.y += yy[t.z];
            h.d += A;
            if (0 <= h.x && h.x <= n && 0 <= h.y && h.y <= m)
                q.push(h);
        }
        else
        {
            for (int i = 0; i < 4; ++i)
            {
                ban h = t;
                h.x += xx[i];
                h.y += yy[i];
                h.d += C;
                if (0 <= h.x && h.x <= n && 0 <= h.y && h.y <= m)
                    q.push(h);
            }
            for (int i = 0; i < 4; ++i)
            {
                ban h = t;
                h.d += B;
                h.z = i;
                q.push(h);
            }
        }
    }
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    ios_base::sync_with_stdio(false), cin.tie(0);

    int tt = 1;
    //cin >> tt;
    while (tt--)
    {
        solv();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 7888 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 48 ms 11680 KB Output is correct
4 Correct 19 ms 7892 KB Output is correct
5 Correct 77 ms 11280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 7896 KB Output is correct
2 Correct 10 ms 6368 KB Output is correct
3 Correct 78 ms 18916 KB Output is correct
4 Correct 402 ms 18024 KB Output is correct
5 Correct 85 ms 18620 KB Output is correct
6 Correct 165 ms 17984 KB Output is correct
7 Correct 36 ms 17688 KB Output is correct
8 Correct 49 ms 18896 KB Output is correct
9 Correct 10 ms 6400 KB Output is correct
10 Correct 10 ms 8936 KB Output is correct
11 Correct 94 ms 31456 KB Output is correct
12 Correct 91 ms 29884 KB Output is correct
13 Correct 116 ms 18880 KB Output is correct
14 Correct 32 ms 17900 KB Output is correct
15 Correct 6 ms 5744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 7888 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 48 ms 11680 KB Output is correct
4 Correct 19 ms 7892 KB Output is correct
5 Correct 77 ms 11280 KB Output is correct
6 Correct 17 ms 7896 KB Output is correct
7 Correct 10 ms 6368 KB Output is correct
8 Correct 78 ms 18916 KB Output is correct
9 Correct 402 ms 18024 KB Output is correct
10 Correct 85 ms 18620 KB Output is correct
11 Correct 165 ms 17984 KB Output is correct
12 Correct 36 ms 17688 KB Output is correct
13 Correct 49 ms 18896 KB Output is correct
14 Correct 10 ms 6400 KB Output is correct
15 Correct 10 ms 8936 KB Output is correct
16 Correct 94 ms 31456 KB Output is correct
17 Correct 91 ms 29884 KB Output is correct
18 Correct 116 ms 18880 KB Output is correct
19 Correct 32 ms 17900 KB Output is correct
20 Correct 6 ms 5744 KB Output is correct
21 Correct 31 ms 6108 KB Output is correct
22 Correct 220 ms 17344 KB Output is correct
23 Correct 270 ms 30940 KB Output is correct
24 Correct 156 ms 18400 KB Output is correct
25 Correct 179 ms 17604 KB Output is correct
26 Correct 255 ms 19012 KB Output is correct
27 Correct 137 ms 5744 KB Output is correct
28 Correct 261 ms 5920 KB Output is correct
29 Correct 405 ms 19860 KB Output is correct
30 Correct 210 ms 8392 KB Output is correct
31 Correct 23 ms 11768 KB Output is correct
32 Correct 56 ms 19084 KB Output is correct
33 Correct 168 ms 18100 KB Output is correct
34 Correct 14 ms 7936 KB Output is correct
35 Correct 239 ms 6800 KB Output is correct