結果

問題 No.1283 Extra Fee
ユーザー 0w10w1
提出日時 2020-11-15 14:38:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,277 bytes
コンパイル時間 2,749 ms
コンパイル使用メモリ 221,640 KB
実行使用メモリ 23,208 KB
最終ジャッジ日時 2023-09-30 06:57:58
合計ジャッジ時間 8,107 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 12 ms
4,668 KB
testcase_12 AC 14 ms
4,376 KB
testcase_13 AC 9 ms
4,376 KB
testcase_14 AC 40 ms
6,060 KB
testcase_15 AC 63 ms
7,648 KB
testcase_16 AC 13 ms
4,472 KB
testcase_17 AC 211 ms
21,916 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 169 ms
18,268 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 229 ms
23,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);

  int N, M; {
    cin >> N >> M;
  }

  vector<vector<int>> C(N, vector<int>(N)); {
    for (int i = 0; i < M; ++i) {
      int H, W, _C;
      cin >> H >> W >> _C;
      C[H - 1][W - 1] = _C;
    }
  }

  const int64_t INF = (int64_t) 1 << 60;

  vector<vector<vector<int64_t>>> dis(N, vector<vector<int64_t>>(N, vector<int64_t>(2, INF))); {
    set<tuple<int64_t, int, int, int>> bag;
    bag.emplace(dis[0][0][0] = 0, 0, 0, 0);
    while (bag.size()) {
      int64_t d;
      int x, y, t;
      tie(d, x, y, t) = *bag.begin(); 
      bag.erase(bag.begin());
      if (d != dis[x][y][t]) continue;
      const int dx[] = { 0, 1, 0, -1 };
      const int dy[] = { 1, 0, -1, 0 };
      for (int _ = 0; _ < 4; ++_) {
        int nx = x + dx[_];
        int ny = y + dy[_];
        if (nx < 0 || nx == N || ny < 0 || ny == N) continue;
        if (d + 1 + C[nx][ny] < dis[nx][ny][t]) {
          bag.emplace(dis[nx][ny][t] = d + 1 + C[nx][ny], nx, ny, t);
        }
        if (t == 0 && d + 1 < dis[nx][ny][1]) {
          bag.emplace(dis[nx][ny][1] = d + 1, nx, ny, 1);
        }
      }
    }
  }

  int res = min(dis[N - 1][N - 1][0], dis[N - 1][N - 1][1]);
  cout << res << endl;
}
0