abc_e 为什么样例未过
  • 板块灌水区
  • 楼主lkjzyd20
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/12/14 21:50
  • 上次更新2024/12/15 09:16:27
查看原帖
abc_e 为什么样例未过
661638
lkjzyd20楼主2024/12/14 21:50
#include <bits/stdc++.h>
#define rep(i, l, r) for(int i = l; i <= r; ++ i)
#define per(i, r, l) for(int i = r; i >= l; -- i)

using namespace std;

typedef long long ll;
const int N = 505;
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};

struct Node
{
    ll s;
    ll ss;
    int x, y;
    bool operator<(const Node &o) const { return s > o.s; }
};

ll g[N][N];
bool vis[N][N];
priority_queue<Node> pq;

int h, w, x, p, q;

void solve()
{
    scanf("%d%d%d", &h, &w, &x);
    scanf("%d%d", &p, &q);
    rep(i, 1, h)
    {
        rep(j, 1, w)
        {
            scanf("%lld", &g[i][j]);
            vis[i][j] = false;
        }
    }

    pq.push({0, g[p][q], p, q});
    vis[p][q] = true;
    ll ans = g[p][q];

    for (;;)
    {
        if (pq.empty())
            break;

        Node cur = pq.top();
        pq.pop();

        rep(d, 0, 3)
        {
            int nx = cur.x + dx[d], ny = cur.y + dy[d];
            if (nx < 1 || nx > h || ny < 1 || ny > w || vis[nx][ny])
                continue;

            if (g[nx][ny] * x < cur.ss)
            {
                pq.push({g[nx][ny], g[nx][ny] + cur.ss, nx, ny});
                vis[nx][ny] = true;
                ans = max(ans, g[nx][ny] + cur.ss);
            }
        }
    }

    printf("%lld\n", ans);
}

int main()
{
    solve();
    return 0;
}
2024/12/14 21:50
加载中...