結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-01-17 22:58:56 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,417 bytes |
| コンパイル時間 | 1,442 ms |
| コンパイル使用メモリ | 145,520 KB |
| 実行使用メモリ | 1,136,884 KB |
| 最終ジャッジ日時 | 2024-11-30 16:08:47 |
| 合計ジャッジ時間 | 33,992 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 5 WA * 6 TLE * 5 MLE * 5 |
ソースコード
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
typedef long long int64;
typedef pair<int,int> P;
typedef tuple<int,int,P> TP;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
void bfs(int h, int w, vector<string>& a, vector<vector<int64>>& ans) {
priority_queue<TP, vector<TP>, greater<TP>> q;
q.emplace(0, 0, P(0,0));
while(!q.empty()) {
int c,kc,x,y;
P p;
tie(c, kc, p) = q.top();
q.pop();
tie(x,y) = p;
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, P(xi, yi));
}
}
}
int main() {
int h,w;
cin >> h >> w;
vector<string> a(h);
for (int i=0; i<h; i++) cin >> a[i];
vector<vector<int64>> ans(h, vector<int64> (w,-1));
bfs(h,w,a,ans);
cout << ans[h-1][w-1] << endl;
}