結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
どらら
|
| 提出日時 | 2020-01-17 21:57:14 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,155 bytes |
| コンパイル時間 | 856 ms |
| コンパイル使用メモリ | 78,332 KB |
| 実行使用メモリ | 116,160 KB |
| 最終ジャッジ日時 | 2024-06-25 19:51:42 |
| 合計ジャッジ時間 | 7,711 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | TLE * 1 -- * 20 |
ソースコード
#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;
}
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);
}
queue<ST> que;
que.push(ST(0, 0, 0, 0));
while(!que.empty()){
ST st = que.front(); 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;
}
どらら