提出 #54603261


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update>  ordered_set;
// member functions : order_of_key(k){no_of_ele < k} find_by_order(k){kth ele}

const ll M = 998244353;
const ll N = 2e5 + 69;
const ll lmax = 2e18;
const ll lmin = -2e18;
//  ... --- ... 

// --------------------------------------------------------------
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
struct comp {
    bool operator()(const vector<ll> &a, const vector<ll> &b)
    {
        if(a[0] != b[0])
            return a[0] > b[0];
        if(a[1] != b[1])
            return a[1] < b[1];
        return true;
    }
};
// --------------------------------------------------------------

void solve()
{
    ll h, w, k, s_x, s_y; 
    cin >> h >> w >> k >> s_x >> s_y;
    vector<vector<ll>> a(h + 1, vector<ll> (w + 1)), dp(h + 1, vector<ll> (w + 1, -1));
    for(int i = 1; i <= h; i++)
        for(int j = 1; j <= w; j++)
            cin >> a[i][j];
    priority_queue<vector<ll>, vector<vector<ll>>, comp> pq;
    pq.push({0, 0, s_x, s_y}); // moves, cost
    dp[s_x][s_y] = 0;
    while(!pq.empty())
    {
        auto p = pq.top();
        pq.pop();
        // go in all directions and if not visited visit the cell
        for(int i = 0; i < 4; i++)
        {
            int x = p[2] + dx[i], y = p[3] + dy[i];
            if(x > 0 && y > 0 && x <= h && y <= w && dp[x][y] == -1)
            {
                dp[x][y] = dp[p[2]][p[3]] + a[x][y];
                pq.push({p[0] + 1, dp[x][y], x, y});
            }
        }
    }
    ll ans = a[s_x][s_y] * k;
    for(int i = 1; i <= h; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            int dist = abs(i - s_x) + abs(j - s_y);
            if(dist <= k)
            {
                ans = max(ans, dp[i][j] + ((k - dist) * a[i][j]));
            }
        }
    }
    cout << ans;
    // 100000000000
    // 100000000200
}

int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    solve();
    return 0;
}

提出情報

提出日時
問題 G - AtCoder Tour
ユーザ jeal0uspengu1n
言語 C++ 20 (gcc 12.2)
得点 0
コード長 2404 Byte
結果 WA
実行時間 2 ms
メモリ 3632 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 550
結果
AC × 2
AC × 23
WA × 13
セット名 テストケース
Sample sample00.txt, sample01.txt
All sample00.txt, sample01.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt
ケース名 結果 実行時間 メモリ
sample00.txt AC 1 ms 3408 KiB
sample01.txt AC 1 ms 3592 KiB
testcase00.txt AC 1 ms 3380 KiB
testcase01.txt AC 1 ms 3560 KiB
testcase02.txt AC 2 ms 3508 KiB
testcase03.txt AC 1 ms 3404 KiB
testcase04.txt AC 2 ms 3572 KiB
testcase05.txt AC 1 ms 3492 KiB
testcase06.txt AC 1 ms 3488 KiB
testcase07.txt AC 1 ms 3500 KiB
testcase08.txt AC 2 ms 3632 KiB
testcase09.txt WA 1 ms 3460 KiB
testcase10.txt AC 1 ms 3500 KiB
testcase11.txt AC 1 ms 3560 KiB
testcase12.txt AC 2 ms 3488 KiB
testcase13.txt WA 1 ms 3492 KiB
testcase14.txt AC 1 ms 3552 KiB
testcase15.txt WA 1 ms 3564 KiB
testcase16.txt WA 1 ms 3568 KiB
testcase17.txt WA 1 ms 3428 KiB
testcase18.txt WA 2 ms 3560 KiB
testcase19.txt WA 1 ms 3424 KiB
testcase20.txt WA 1 ms 3568 KiB
testcase21.txt AC 1 ms 3412 KiB
testcase22.txt AC 1 ms 3572 KiB
testcase23.txt AC 1 ms 3544 KiB
testcase24.txt WA 1 ms 3460 KiB
testcase25.txt WA 1 ms 3540 KiB
testcase26.txt AC 2 ms 3572 KiB
testcase27.txt AC 1 ms 3532 KiB
testcase28.txt AC 1 ms 3572 KiB
testcase29.txt WA 1 ms 3536 KiB
testcase30.txt WA 1 ms 3460 KiB
testcase31.txt AC 1 ms 3432 KiB
testcase32.txt AC 1 ms 3568 KiB
testcase33.txt WA 1 ms 3468 KiB