結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
tko919
|
| 提出日時 | 2020-01-17 21:55:43 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 380 ms / 2,000 ms |
| コード長 | 1,347 bytes |
| コンパイル時間 | 1,943 ms |
| コンパイル使用メモリ | 172,948 KB |
| 実行使用メモリ | 23,424 KB |
| 最終ジャッジ日時 | 2024-11-07 11:29:47 |
| 合計ジャッジ時間 | 6,040 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end
typedef pair<int,int> P;
typedef pair<P,P> T;
int dx[]={0,1},dy[]={1,0};
char g[2010][2010];
int res[2010][2010];
int main(){
int h,w; scanf("%d%d",&h,&w);
rep(i,0,h)rep(j,0,w){
cin>>g[i][j];
res[i][j]=inf;
} res[0][0]=0;
queue<T> que; que.push({{0,0},{0,0}});
while(!que.empty()){
T t=que.front(); que.pop();
int d=t.first.first,add=t.first.second;
int x=t.second.first,y=t.second.second;
if(res[x][y]!=d+add)continue;
rep(i,0,2){
int tx=x+dx[i],ty=y+dy[i],td=d+1,tadd=add;
if(tx<0||tx>=h||ty<0||ty>=w)continue;
if(g[tx][ty]=='k')tadd+=td;
if(chmin(res[tx][ty],td+tadd))que.push({{td,tadd},{tx,ty}});
}
}
printf("%d\n",res[h-1][w-1]);
return 0;
}
tko919