結果

問題 No.1283 Extra Fee
ユーザー SSRSSSRS
提出日時 2020-11-06 21:45:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 469 ms / 2,000 ms
コード長 1,246 bytes
コンパイル時間 1,883 ms
コンパイル使用メモリ 185,232 KB
実行使用メモリ 30,376 KB
最終ジャッジ日時 2023-08-10 05:55:52
合計ジャッジ時間 9,015 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 19 ms
4,780 KB
testcase_12 AC 22 ms
4,432 KB
testcase_13 AC 15 ms
4,376 KB
testcase_14 AC 66 ms
5,628 KB
testcase_15 AC 106 ms
7,332 KB
testcase_16 AC 22 ms
4,376 KB
testcase_17 AC 401 ms
29,732 KB
testcase_18 AC 377 ms
17,088 KB
testcase_19 AC 403 ms
17,636 KB
testcase_20 AC 373 ms
16,736 KB
testcase_21 AC 381 ms
17,100 KB
testcase_22 AC 341 ms
15,528 KB
testcase_23 AC 400 ms
17,824 KB
testcase_24 AC 469 ms
17,944 KB
testcase_25 AC 419 ms
18,384 KB
testcase_26 AC 417 ms
18,044 KB
testcase_27 AC 419 ms
18,176 KB
testcase_28 AC 419 ms
18,112 KB
testcase_29 AC 438 ms
30,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
vector<int> dy = {1, 0, -1, 0};
vector<int> dx = {0, 1, 0, -1};
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> A(N, vector<int>(N, 0));
  for (int i = 0; i < M; i++){
    int h, w, c;
    cin >> h >> w >> c;
    h--;
    w--;
    A[h][w] = c;
  }
  priority_queue<tuple<long long, int, int, int>, vector<tuple<long long, int, int, int>>, greater<tuple<long long, int, int, int>>> pq;
  vector<vector<vector<long long>>> cost(N, vector<vector<long long>>(N, vector<long long>(2, -1)));
  pq.push(make_tuple(0, 0, 0, 0));
  while (!pq.empty()){
    long long sum = get<0>(pq.top());
    int y = get<1>(pq.top());
    int x = get<2>(pq.top());
    int u = get<3>(pq.top());
    pq.pop();
    if (cost[y][x][u] == -1){
      cost[y][x][u] = sum;
      for (int i = 0; i < 4; i++){
        int y2 = y + dy[i];
        int x2 = x + dx[i];
        if (0 <= y2 && y2 < N && 0 <= x2 && x2 < N){
          if (cost[y2][x2][u] == -1){
            pq.push(make_tuple(sum + A[y2][x2] + 1, y2, x2, u));
          }
          if (u == 0 && cost[y2][x2][1] == -1){
            pq.push(make_tuple(sum + 1, y2, x2, 1));
          }
        }
      }
    }
  }
  cout << cost[N - 1][N - 1][1] << endl;
}
0