結果

問題 No.1283 Extra Fee
ユーザー 0w10w1
提出日時 2020-11-15 14:38:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 220 ms / 2,000 ms
コード長 1,281 bytes
コンパイル時間 2,484 ms
コンパイル使用メモリ 224,376 KB
実行使用メモリ 23,296 KB
最終ジャッジ日時 2024-04-27 23:41:41
合計ジャッジ時間 6,172 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,948 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 11 ms
6,944 KB
testcase_12 AC 11 ms
6,940 KB
testcase_13 AC 8 ms
6,944 KB
testcase_14 AC 36 ms
6,940 KB
testcase_15 AC 56 ms
7,680 KB
testcase_16 AC 12 ms
6,940 KB
testcase_17 AC 168 ms
21,888 KB
testcase_18 AC 197 ms
17,152 KB
testcase_19 AC 211 ms
17,792 KB
testcase_20 AC 198 ms
16,896 KB
testcase_21 AC 204 ms
17,152 KB
testcase_22 AC 173 ms
15,616 KB
testcase_23 AC 149 ms
18,304 KB
testcase_24 AC 163 ms
18,176 KB
testcase_25 AC 215 ms
18,304 KB
testcase_26 AC 217 ms
18,176 KB
testcase_27 AC 220 ms
18,176 KB
testcase_28 AC 218 ms
18,304 KB
testcase_29 AC 184 ms
23,296 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);
        }
      }
    }
  }

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