結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
koyopro
|
| 提出日時 | 2020-02-05 01:12:53 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,374 bytes |
| コンパイル時間 | 1,322 ms |
| コンパイル使用メモリ | 164,368 KB |
| 実行使用メモリ | 100,524 KB |
| 最終ジャッジ日時 | 2024-09-21 07:53:22 |
| 合計ジャッジ時間 | 8,184 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 WA * 5 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define array2(type, x, y) array<array<type, y>, x>
#define vector2(type) vector<vector<type> >
#define out(...) printf(__VA_ARGS__)
int dxy[] = {0, 1, 0, -1, 0};
void solve();
signed main()
{
#if DEBUG
std::ifstream in("input.txt");
std::cin.rdbuf(in.rdbuf());
#endif
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
/*================================*/
#if DEBUG
#define SIZE 2000
#else
#define SIZE 2000
#endif
int H,W;
// 合計コスト(route, trick)
int C[SIZE][SIZE][2];
// トリックコスト(route, trick)
int T[SIZE][SIZE][2];
int K[SIZE][SIZE];
//typedef pair<int,int> pos;
struct Pos{
int h, w, c;
Pos(): h(0),w(0),c(0){};
Pos(int h, int w, int c): h(h),w(w),c(c){};
bool operator < (const Pos &q) const {
return q.c < c;
};
};
void solve() {
cin>>H>>W;
char c;
REP(h,H)REP(w,W) {
cin>>c;
K[h][w]=(c=='k');
}
REP(h,SIZE)REP(w,SIZE)REP(i,2) C[h][w][i]=INT_MAX;
REP(i,2) C[0][0][i]=0;
REP(i,2) T[0][0][i]=0;
priority_queue<Pos> que;
que.push(Pos(0,0,0));
while(!que.empty()) {
Pos p = que.top();
que.pop();
int h = p.h;
int w = p.w;
if (p.c > C[h][w][0] + C[h][w][1]) continue;
REP(d,4) {
int nh = h + dxy[d];
int nw = w + dxy[d+1];
if (nh<0||nw<0||nh>=H||nw>=W) continue;
// 合計コスト
int routeCost = C[h][w][0] + 1;
int trickCost = C[h][w][1] + (K[nh][nw] ? routeCost : 0);
int nCost = trickCost + routeCost;
int cCost = C[nh][nw][0]+C[nh][nw][1];
if (nCost < cCost || (nCost == cCost && routeCost < C[nh][nw][0])) {
C[nh][nw][0] = routeCost;
C[nh][nw][1] = trickCost;
que.push(Pos(nh,nw, routeCost+trickCost));
}
}
}
cout << C[H-1][W-1][0]+C[H-1][W-1][1] << endl;
}
koyopro