結果
問題 | No.1283 Extra Fee |
ユーザー | 🍮かんプリン |
提出日時 | 2020-11-06 23:10:30 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 431 ms / 2,000 ms |
コード長 | 2,696 bytes |
コンパイル時間 | 1,765 ms |
コンパイル使用メモリ | 184,876 KB |
実行使用メモリ | 74,884 KB |
最終ジャッジ日時 | 2023-08-10 06:08:01 |
合計ジャッジ時間 | 9,037 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,376 KB |
testcase_09 | AC | 2 ms
4,380 KB |
testcase_10 | AC | 1 ms
4,376 KB |
testcase_11 | AC | 18 ms
6,912 KB |
testcase_12 | AC | 21 ms
7,668 KB |
testcase_13 | AC | 15 ms
5,960 KB |
testcase_14 | AC | 66 ms
15,732 KB |
testcase_15 | AC | 109 ms
23,220 KB |
testcase_16 | AC | 23 ms
7,280 KB |
testcase_17 | AC | 294 ms
64,560 KB |
testcase_18 | AC | 391 ms
69,336 KB |
testcase_19 | AC | 411 ms
72,276 KB |
testcase_20 | AC | 392 ms
68,052 KB |
testcase_21 | AC | 401 ms
69,076 KB |
testcase_22 | AC | 361 ms
61,984 KB |
testcase_23 | AC | 364 ms
74,444 KB |
testcase_24 | AC | 427 ms
74,576 KB |
testcase_25 | AC | 423 ms
74,712 KB |
testcase_26 | AC | 420 ms
74,584 KB |
testcase_27 | AC | 431 ms
74,580 KB |
testcase_28 | AC | 417 ms
74,884 KB |
testcase_29 | AC | 312 ms
70,008 KB |
ソースコード
/** * @FileName a.cpp * @Author kanpurin * @Created 2020.11.06 23:10:25 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; template<typename T> struct Dijkstra { private: int V; struct edge { int to; T cost; }; vector<vector<edge>> G; public: const T inf = numeric_limits<T>::max(); vector<T> d; Dijkstra() {} Dijkstra(int V) : V(V) { G.resize(V); } Dijkstra<T>& operator=(const Dijkstra<T>& obj) { this->V = obj.V; this->G = obj.G; this->d = obj.d; return *this; } void add_edge(int from, int to, T weight, bool directed = false) { G[from].push_back({to,weight}); if (!directed) G[to].push_back({from,weight}); } int add_vertex() { G.push_back(vector<edge>()); return V++; } void build(int s) { d.assign(V, inf); typedef tuple<T, int> P; priority_queue<P, vector<P>, greater<P>> pq; d[s] = 0; pq.push(P(d[s], s)); while (!pq.empty()) { P p = pq.top(); pq.pop(); int v = get<1>(p); if (d[v] < get<0>(p)) continue; for (const edge &e : G[v]) { if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; pq.push(P(d[e.to], e.to)); } } } } }; int n; int id(int h,int w,int used) { return h * n + w + n*n*used; } int main() { int m;cin >> n >> m; Dijkstra<ll> g(2*n*n+1); int goal = 2*n*n; int dx[] = {0,1,0,-1}, dy[] = {1,0,-1,0}; vector<vector<int>> ryoukin(n,vector<int>(n,0)); for (int i = 0; i < m; i++) { int h,w,c;cin >> h >> w >> c; ryoukin[h-1][w-1] = c; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < 4; k++) { int x = dx[k] + i, y = dy[k] + j; if (x < 0 || x >= n || y < 0 || y >= n) continue; if (ryoukin[x][y] > 0) { g.add_edge(id(i,j,0),id(x,y,0),ryoukin[x][y]+1,true); g.add_edge(id(i,j,1),id(x,y,1),ryoukin[x][y]+1,true); g.add_edge(id(i,j,0),id(x,y,1),1,true); } else { g.add_edge(id(i,j,0),id(x,y,0),1,true); g.add_edge(id(i,j,1),id(x,y,1),1,true); } } } } g.add_edge(id(n-1,n-1,0),goal,0,true); g.add_edge(id(n-1,n-1,1),goal,0,true); g.build(id(0,0,0)); cout << g.d[goal] << endl; return 0; }