結果
問題 |
No.971 いたずらっ子
|
ユーザー |
![]() |
提出日時 | 2020-01-17 23:06:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,185 bytes |
コンパイル時間 | 1,906 ms |
コンパイル使用メモリ | 176,128 KB |
実行使用メモリ | 66,688 KB |
最終ジャッジ日時 | 2024-06-26 00:02:57 |
合計ジャッジ時間 | 7,660 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 WA * 14 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; struct P { ll x, y, bs, dist; }; int main(){ ll h, w; scanf("%lld %lld", &h, &w); vector<vector<ll>> fig(h, vector<ll>(w)); for(ll i=0; i<h; i++){ string s; cin>>s; for(ll j=0; j<w; j++) fig[i][j] = (s[j]=='k'); } ll dx[] = {0, 1, 0, -1}; ll dy[] = {1, 0, -1, 0}; vector<vector<ll>> ans(h, vector<ll>(w, 1e11)); queue<P> que; P p = {0, 0, -1, 0}; que.push(p); while(!que.empty()){ p = que.front(); que.pop(); if(fig[p.x][p.y]) p.dist += max(0ll, p.dist-p.bs*p.bs); if(ans[p.x][p.y]<=p.dist) continue; ans[p.x][p.y] = p.dist; for(ll i=0; i<4; i++){ ll tx = p.x-dx[i], ty = p.y-dy[i]; if(0<=tx && tx<h and 0<=ty && ty<w){ P np = {tx, ty, p.bs+fig[tx][ty], p.dist+1}; que.push(np); } } } printf("%lld\n", ans[h-1][w-1]); return 0; }