結果
問題 | No.1283 Extra Fee |
ユーザー | Haa |
提出日時 | 2020-11-06 22:25:28 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 247 ms / 2,000 ms |
コード長 | 1,423 bytes |
コンパイル時間 | 1,963 ms |
コンパイル使用メモリ | 178,148 KB |
実行使用メモリ | 12,484 KB |
最終ジャッジ日時 | 2024-04-27 23:20:08 |
合計ジャッジ時間 | 5,598 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 3 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 3 ms
6,944 KB |
testcase_10 | AC | 3 ms
6,940 KB |
testcase_11 | AC | 9 ms
6,944 KB |
testcase_12 | AC | 12 ms
6,944 KB |
testcase_13 | AC | 10 ms
6,940 KB |
testcase_14 | AC | 39 ms
6,940 KB |
testcase_15 | AC | 63 ms
6,944 KB |
testcase_16 | AC | 14 ms
6,940 KB |
testcase_17 | AC | 119 ms
12,000 KB |
testcase_18 | AC | 216 ms
9,088 KB |
testcase_19 | AC | 239 ms
9,216 KB |
testcase_20 | AC | 220 ms
8,960 KB |
testcase_21 | AC | 247 ms
9,088 KB |
testcase_22 | AC | 215 ms
8,576 KB |
testcase_23 | AC | 168 ms
9,472 KB |
testcase_24 | AC | 228 ms
9,344 KB |
testcase_25 | AC | 245 ms
9,344 KB |
testcase_26 | AC | 238 ms
9,344 KB |
testcase_27 | AC | 239 ms
9,472 KB |
testcase_28 | AC | 244 ms
9,344 KB |
testcase_29 | AC | 124 ms
12,484 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll,ll> P; typedef vector<ll> VI; typedef vector<VI> VVI; #define REP(i,n) for(int i=0;i<n;i++) #define ALL(v) v.begin(),v.end() const ll MOD=1000000007; const ll INF=1e18; struct xy { int x; int y; ll d; bool f; bool operator<(const xy &another) const {return d > another.d;}; }; int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; int n; VVI c(510,VI(510,0)); ll bfs(int sx, int sy, int gx, int gy){ priority_queue<xy> q; q.push({sx,sy,0,0}); VVI dis0(n, VI(n, INF)); VVI dis1(n, VI(n, INF)); dis0[0][0]=0; while (!q.empty()) { int x=q.top().x, y=q.top().y; ll d=q.top().d; bool f=q.top().f; q.pop(); if(!f&&d>dis0[x][y]) continue; if(f&&d>dis1[x][y]) continue; REP(k,4){ int tox=x+dx[k], toy=y+dy[k]; if(tox<0||tox>=n||toy<0||toy>=n) continue; if(!f){ if(dis0[tox][toy]>d+1+c[tox][toy]){ dis0[tox][toy]=d+1+c[tox][toy]; q.push({tox,toy,d+1+c[tox][toy],0}); } if(dis1[tox][toy]>d+1){ dis1[tox][toy]=d+1; q.push({tox,toy,d+1,1}); } } else{ if(dis1[tox][toy]>d+1+c[tox][toy]){ dis1[tox][toy]=d+1+c[tox][toy]; q.push({tox,toy,d+1+c[tox][toy],1}); } } } } return dis1[gx][gy]; } int main(){ int m; cin >> n >> m; int h, w, x; REP(i,m){ cin >> h >> w >> x; h--, w--; c[h][w]=x; } cout << bfs(0,0,n-1,n-1) << endl; return 0; }