結果
問題 |
No.971 いたずらっ子
|
ユーザー |
![]() |
提出日時 | 2020-06-04 01:23:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,770 bytes |
コンパイル時間 | 756 ms |
コンパイル使用メモリ | 91,328 KB |
実行使用メモリ | 40,836 KB |
最終ジャッジ日時 | 2024-11-27 03:32:51 |
合計ジャッジ時間 | 7,781 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 WA * 5 |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <set> #include <map> using namespace std; typedef long long ll; typedef pair<int, int> Pii; typedef pair<ll, ll> Pll; typedef pair<Pll, Pii> P; int H, W; char a[2000][2000]; ll dist[2000][2000]; ll dist1[2000][2000]; const ll INF = 1e15; int dh[4] = {-1, 1, 0, 0}; int dw[4] = {0, 0, -1, 1}; bool in_field(int h, int w){ return h >= 0 && h < H && w >= 0 && w < W; } void dijkstra(){ priority_queue<P, vector<P>, greater<P>> que; for(int i = 0; i < H; i++){ for(int j = 0; j < W; j++){ dist[i][j] = INF; } } dist[0][0] = 0; que.push(P(Pll(0, 0), Pii(0, 0))); while(!que.empty()){ P p = que.top();que.pop(); Pii v = p.second; int h = v.first, w = v.second; if(dist[h][w] < p.first.first) continue; for(int i = 0; i < 4; i++){ int h_to = h+dh[i], w_to = w+dw[i]; if(!in_field(h_to, w_to)) continue; ll cost = (a[h_to][w_to] == '.' ? 1 : (p.first.second+2)); if(dist[h][w] + cost < dist[h_to][w_to]){ dist[h_to][w_to] = dist[h][w] + cost; que.push(P(Pll(dist[h_to][w_to], p.first.second+1), Pii(h_to, w_to))); } } } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> H >> W; for(int i = 0; i < H; i++){ for(int j = 0; j < W; j++){ cin >> a[i][j]; } } dijkstra(); // for(int i = 0; i < H; i++){ // for(int j = 0; j < W; j++){ // cout << dist[i][j] << ' '; // } // cout << endl; // } cout << dist[H-1][W-1] << endl; }