結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-01-17 23:19:11 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,333 bytes |
| コンパイル時間 | 1,242 ms |
| コンパイル使用メモリ | 145,068 KB |
| 実行使用メモリ | 764,896 KB |
| 最終ジャッジ日時 | 2024-11-30 16:12:13 |
| 合計ジャッジ時間 | 33,575 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 6 WA * 6 TLE * 7 MLE * 2 |
ソースコード
#include <iostream>
#include <queue>
#include <numeric>
#include <vector>
#include <iomanip>
#include <utility>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
//struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
typedef tuple<int,int,short, short> TP;
char dx[4]={1,0,-1,0};
char dy[4]={0,1,0,-1};
short h,w;
char a[2000][2000];
int ans[2000][2000];
priority_queue<TP, vector<TP>, greater<>> q;
void bfs() {
q.emplace(0, 0, 0, 0);
int c,kc;
short x,y;
while(!q.empty()) {
tie(c, kc, x,y) = q.top(); q.pop();
if (x < 0 || x >= w) continue;
if (y < 0 || y >= h) continue;
if (ans[y][x] >= 0) continue;
ans[y][x] = c;
if (a[y][x] == 'k') {
c = c*2 + 1 - kc;
kc++;
}
else c++;
for (short i=0; i<4; i++) {
short xi = x + dx[i];
short yi = y + dy[i];
if (xi < 0 || xi >= w) continue;
if (yi < 0 || yi >= h) continue;
q.emplace(c, kc, xi, yi);
}
}
}
int main() {
cin >> h >> w;
for (short i=0; i<h; i++) {
for (short j=0; j<w; j++) {
cin >> a[i][j];
ans[i][j] = -1;
}
}
bfs();
cout << ans[h-1][w-1] << endl;
}