結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-01-17 23:09:31 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,289 bytes |
| コンパイル時間 | 1,560 ms |
| コンパイル使用メモリ | 147,032 KB |
| 実行使用メモリ | 561,624 KB |
| 最終ジャッジ日時 | 2024-11-30 16:10:43 |
| 合計ジャッジ時間 | 35,325 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 4 WA * 6 TLE * 6 MLE * 5 |
ソースコード
#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,int,int> TP;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int h,w;
vector<string> a;
vector<vector<int>> ans;
priority_queue<TP, vector<TP>, greater<>> q;
void bfs() {
q.emplace(0, 0, 0, 0);
int c,kc,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 (int i=0; i<4; i++) {
int xi = x + dx[i];
int 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;
a = vector<string>(h);
for (int i=0; i<h; i++) cin >> a[i];
ans = vector<vector<int>>(h, vector<int> (w,-1));
bfs();
cout << ans[h-1][w-1] << endl;
}