結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
どらら
|
| 提出日時 | 2020-01-17 22:00:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,185 ms / 2,000 ms |
| コード長 | 1,303 bytes |
| コンパイル時間 | 1,183 ms |
| コンパイル使用メモリ | 78,832 KB |
| 実行使用メモリ | 70,528 KB |
| 最終ジャッジ日時 | 2024-11-07 11:30:44 |
| 合計ジャッジ時間 | 12,202 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
ソースコード
#include <iostream>
#include <queue>
#include <vector>
#define ll long long
using namespace std;
struct ST {
int y, x;
int dist;
int tm;
ST():dist(-1),tm(-1){}
ST(int y, int x, int dist, int tm):y(y),x(x),dist(dist),tm(tm){}
};
bool operator<(const ST& a, const ST& b){
if(a.tm == b.tm) return a.dist < b.dist;
return a.tm < b.tm;
}
bool operator>(const ST& a, const ST& b){
if(a.tm == b.tm) return a.dist > b.dist;
return a.tm > b.tm;
}
ST dp[2005][2005];
int main(){
int H, W;
cin >> H >> W;
vector<string> field;
for(int i=0; i<H; i++){
string s;
cin >> s;
field.push_back(s);
}
priority_queue<ST,vector<ST>,greater<ST>> que;
que.push(ST(0, 0, 0, 0));
while(!que.empty()){
ST st = que.top(); que.pop();
if(dp[st.y][st.x].tm == -1 || st < dp[st.y][st.x]){
dp[st.y][st.x] = st;
if(st.x+1<W){
que.push(ST(st.y, st.x+1, st.dist+1, st.tm + 1 + (field[st.y][st.x+1]=='k'?st.dist+1:0)));
}
if(st.y+1<H){
que.push(ST(st.y+1, st.x, st.dist+1, st.tm + 1 + (field[st.y+1][st.x]=='k'?st.dist+1:0)));
}
}
}
cout << dp[H-1][W-1].tm << endl;
return 0;
}
どらら