結果

問題 No.1283 Extra Fee
ユーザー rogi52rogi52
提出日時 2020-11-07 00:21:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 342 ms / 2,000 ms
コード長 1,216 bytes
コンパイル時間 2,383 ms
コンパイル使用メモリ 220,256 KB
実行使用メモリ 30,712 KB
最終ジャッジ日時 2024-04-27 23:28:13
合計ジャッジ時間 7,075 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 16 ms
6,944 KB
testcase_12 AC 16 ms
6,940 KB
testcase_13 AC 9 ms
6,940 KB
testcase_14 AC 42 ms
6,940 KB
testcase_15 AC 67 ms
7,552 KB
testcase_16 AC 13 ms
6,940 KB
testcase_17 AC 310 ms
29,260 KB
testcase_18 AC 236 ms
17,280 KB
testcase_19 AC 248 ms
17,664 KB
testcase_20 AC 226 ms
16,768 KB
testcase_21 AC 236 ms
16,896 KB
testcase_22 AC 208 ms
15,488 KB
testcase_23 AC 280 ms
18,048 KB
testcase_24 AC 292 ms
18,048 KB
testcase_25 AC 254 ms
18,304 KB
testcase_26 AC 265 ms
18,176 KB
testcase_27 AC 255 ms
18,304 KB
testcase_28 AC 251 ms
18,176 KB
testcase_29 AC 342 ms
30,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);

    int N,M; cin >> N >> M;
    vector<vector<int>> A(N, vector<int> (N,0));
    rep(i,M){
        int h,w,c; cin >> h >> w >> c;
        h--; w--;
        A[h][w] = c;
    }

    priority_queue<tuple<ll,int,int,int>, vector<tuple<ll,int,int,int>>,greater<tuple<ll,int,int,int>>> Q;
    vector<vector<vector<ll>>> cost(N,vector<vector<ll>>(N, vector<ll> (2,-1)));
    Q.push({0,0,0,0});

    while(!Q.empty()){
        auto [sum,y,x,u] = Q.top(); Q.pop();

        if(cost[y][x][u] == -1){
            cost[y][x][u] = sum;

            rep(i,4){
                int ny = y + dy[i];
                int nx = x + dx[i];
                if(ny < 0 || N <= ny || nx < 0 || N <= nx) continue;
                if(cost[ny][nx][u] == -1){
                    Q.push({sum+A[ny][nx]+1, ny, nx, u});
                }
                if(u == 0 && cost[ny][nx][1] == -1){
                    Q.push({sum+1, ny, nx, 1});
                }
            }
        }
    }

    cout << cost[N-1][N-1][1] << '\n';
}
0