結果

問題 No.971 いたずらっ子
ユーザー tko919tko919
提出日時 2020-01-17 21:55:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 334 ms / 2,000 ms
コード長 1,347 bytes
コンパイル時間 1,521 ms
コンパイル使用メモリ 171,600 KB
実行使用メモリ 23,352 KB
最終ジャッジ日時 2023-08-07 07:54:21
合計ジャッジ時間 5,240 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 334 ms
23,268 KB
testcase_01 AC 333 ms
23,352 KB
testcase_02 AC 249 ms
23,240 KB
testcase_03 AC 263 ms
23,324 KB
testcase_04 AC 246 ms
23,048 KB
testcase_05 AC 259 ms
23,228 KB
testcase_06 AC 199 ms
22,804 KB
testcase_07 AC 5 ms
6,052 KB
testcase_08 AC 71 ms
15,852 KB
testcase_09 AC 67 ms
15,944 KB
testcase_10 AC 4 ms
5,708 KB
testcase_11 AC 2 ms
5,684 KB
testcase_12 AC 2 ms
5,636 KB
testcase_13 AC 2 ms
5,564 KB
testcase_14 AC 7 ms
22,284 KB
testcase_15 AC 2 ms
5,648 KB
testcase_16 AC 3 ms
10,716 KB
testcase_17 AC 2 ms
5,588 KB
testcase_18 AC 2 ms
5,524 KB
testcase_19 AC 2 ms
5,620 KB
testcase_20 AC 2 ms
5,588 KB
testcase_21 AC 2 ms
5,556 KB
testcase_22 AC 2 ms
5,636 KB
testcase_23 AC 2 ms
5,588 KB
testcase_24 AC 2 ms
5,612 KB
権限があれば一括ダウンロードができます

ソースコード

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,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;
}
0