結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
NOSS
|
| 提出日時 | 2020-01-17 21:46:47 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 836 ms / 2,000 ms |
| コード長 | 1,220 bytes |
| コンパイル時間 | 2,063 ms |
| コンパイル使用メモリ | 179,372 KB |
| 実行使用メモリ | 42,368 KB |
| 最終ジャッジ日時 | 2024-11-07 11:27:22 |
| 合計ジャッジ時間 | 9,128 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using P = pair<int,int>;
using P3 = pair<ll,P>;
using PP = pair<P, P>;
constexpr int INF = 1<<30;
constexpr ll MOD = (1e9)+7;
constexpr int di[] = {0,1,0,-1};
constexpr int dj[] = {1,0,-1,0};
int main(){
int h, w;
cin >> h >> w;
vector<string> s(h);
for(int i=0;i<h;i++){
cin >> s[i];
}
vector<vector<ll> > d(h, vector<ll>(w, INF));
d[0][0] = 0;
priority_queue<P3,vector<P3>,greater<P3> > que;
que.push(make_pair(0LL,P(0,0)));
while(!que.empty()){
auto p = que.top();
que.pop();
int i = p.second.first, j = p.second.second;
if(d[i][j] < p.first) continue;
for(int k=0;k<2;k++){
int ni = i+di[k], nj=j+dj[k];
if(ni<0||ni>=h)continue;
if(nj<0||nj>=w)continue;
ll nd;
if(s[ni][nj] == '.'){
nd = d[i][j] + 1;
}else{
nd = d[i][j] + 1 + ni + nj;
}
if(d[ni][nj] > nd){
d[ni][nj] = nd;
que.push(make_pair(d[ni][nj],P(ni,nj)));
}
}
}
cout << d[h-1][w-1] << endl;
return 0;
}
NOSS