結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2020-06-04 01:11:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,587 bytes |
| コンパイル時間 | 728 ms |
| コンパイル使用メモリ | 90,068 KB |
| 実行使用メモリ | 70,060 KB |
| 最終ジャッジ日時 | 2024-11-27 03:09:16 |
| 合計ジャッジ時間 | 7,834 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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, 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(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) 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][w] == '.' ? 1 : (dist1[h][w]+1));
if(dist[h][w] + cost < dist[h_to][w_to]){
dist[h_to][w_to] = dist[h][w] + cost;
dist1[h_to][w_to] = dist1[h][w] + 1;
que.push(P(dist[h_to][w_to], 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();
cout << dist[H-1][W-1] << endl;
}
milanis48663220