結果

問題 No.971 いたずらっ子
ユーザー tko919tko919
提出日時 2020-01-17 21:53:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,357 bytes
コンパイル時間 1,525 ms
コンパイル使用メモリ 171,680 KB
実行使用メモリ 33,288 KB
最終ジャッジ日時 2023-09-08 02:35:06
合計ジャッジ時間 8,292 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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,0,1,-1},dy[]={1,-1,0,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,4){
         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;
}
0