結果
問題 | No.1283 Extra Fee |
ユーザー | outline |
提出日時 | 2020-12-09 22:43:55 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 140 ms / 2,000 ms |
コード長 | 2,474 bytes |
コンパイル時間 | 1,632 ms |
コンパイル使用メモリ | 146,400 KB |
実行使用メモリ | 11,960 KB |
最終ジャッジ日時 | 2024-04-27 23:44:38 |
合計ジャッジ時間 | 4,241 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 10 ms
6,944 KB |
testcase_12 | AC | 9 ms
6,944 KB |
testcase_13 | AC | 7 ms
6,940 KB |
testcase_14 | AC | 25 ms
6,944 KB |
testcase_15 | AC | 37 ms
6,940 KB |
testcase_16 | AC | 9 ms
6,944 KB |
testcase_17 | AC | 117 ms
11,036 KB |
testcase_18 | AC | 121 ms
8,064 KB |
testcase_19 | AC | 140 ms
8,148 KB |
testcase_20 | AC | 125 ms
8,088 KB |
testcase_21 | AC | 132 ms
8,112 KB |
testcase_22 | AC | 115 ms
7,736 KB |
testcase_23 | AC | 111 ms
8,304 KB |
testcase_24 | AC | 129 ms
8,108 KB |
testcase_25 | AC | 136 ms
8,280 KB |
testcase_26 | AC | 133 ms
8,360 KB |
testcase_27 | AC | 131 ms
8,384 KB |
testcase_28 | AC | 136 ms
8,308 KB |
testcase_29 | AC | 122 ms
11,960 KB |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <queue> #include <string> #include <map> #include <set> #include <stack> #include <tuple> #include <deque> #include <array> #include <numeric> #include <bitset> #include <iomanip> #include <cassert> #include <chrono> #include <random> #include <limits> #include <iterator> #include <functional> #include <sstream> #include <fstream> #include <complex> #include <cstring> #include <unordered_map> using namespace std; using ll = long long; using P = pair<int, int>; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template<class T> inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template<class T> inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } constexpr ll inf = 1e+17; using Data = tuple<ll, int, int, int>; ll dist[505][505][2]; constexpr int dx[4] = {1, 0, -1, 0}; constexpr int dy[4] = {0, 1, 0, -1}; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N, M; cin >> N >> M; vector<vector<int>> c(N, vector<int>(N)); for(int i = 0; i < M; ++i){ int h, w; cin >> h >> w; --h, --w; cin >> c[h][w]; } for(int i = 0; i < N; ++i){ for(int j = 0; j < N; ++j){ dist[i][j][0] = dist[i][j][1] = inf; } } dist[0][0][0] = 0; priority_queue<Data, vector<Data>, greater<Data>> que; que.emplace(0, 0, 0, 0); while(!que.empty()){ auto [d, x, y , f] = que.top(); que.pop(); if(d > dist[x][y][f]) continue; for(int i = 0; i < 4; ++i){ int nx = x + dx[i], ny = y + dy[i]; if(nx < 0 || nx >= N || ny < 0 || ny >= N) continue; if(f == 1){ if(chmin(dist[nx][ny][1], dist[x][y][1] + 1 + c[nx][ny])){ que.emplace(dist[nx][ny][1], nx, ny, 1); } } else{ if(chmin(dist[nx][ny][1], dist[x][y][0] + 1)){ que.emplace(dist[nx][ny][1], nx, ny, 1); } if(chmin(dist[nx][ny][0], dist[x][y][0] + 1 + c[nx][ny])){ que.emplace(dist[nx][ny][0], nx, ny, 0); } } } } cout << min(dist[N - 1][N - 1][0], dist[N - 1][N - 1][1]) << endl; return 0; }