結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
kotorigasatori1
|
| 提出日時 | 2020-01-17 23:03:50 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,481 bytes |
| コンパイル時間 | 978 ms |
| コンパイル使用メモリ | 79,940 KB |
| 実行使用メモリ | 51,300 KB |
| 最終ジャッジ日時 | 2024-06-25 23:52:42 |
| 合計ジャッジ時間 | 7,763 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 4 |
| other | TLE * 1 -- * 20 |
ソースコード
#include <iostream>
#include <vector>
#include <utility>
#include <deque>
# define INF 10000000
using namespace std;
int main(void){
// Your code here!
int h,w;
cin >> h >> w;
int num[h][w];
char c[h][w];
deque <pair<int,int> > stk_yx;
deque <int> stk_num;
for(int i=0;i<h;i++)for(int j=0;j<w;j++){
cin >> c[i][j];
}
for(int i=0;i<h;i++)for(int j=0;j<w;j++){
num[i][j] = INF;
}
stk_yx.emplace_back(make_pair(0,0));
stk_num.emplace_back(0);
int dx[4] = {0,1,-1,0};
int dy[4] = {1,0,0,-1};
num[0][0] = 0;
while(! stk_yx.empty()){
pair <int,int> temp = stk_yx.front();
long long int temp_num = stk_num.front();
long long int temp_num2;
stk_yx.pop_front();
stk_num.pop_front();
for(int i=0;i<4;i++){
int ny = temp.first + dy[i];
int nx = temp.second + dx[i];
if(ny >= 0 && ny < h && nx >= 0 && nx < w){
temp_num2 = temp_num + 1;
if(c[ny][nx] == 'k')temp_num2 =temp_num2 + nx + ny;
if(num[ny][nx] > temp_num2){
num[ny][nx] = temp_num2;
stk_yx.emplace_back(ny,nx);
stk_num.emplace_back(temp_num2);
}
}
}
}
/*
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cout << num[i][j] << "\t";
}
cout << endl;
}
*/
cout << num[h-1][w-1] << endl;
return 0;
}
kotorigasatori1