結果

問題 No.971 いたずらっ子
ユーザー chocopuuchocopuu
提出日時 2020-01-17 22:18:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,281 bytes
コンパイル時間 3,465 ms
コンパイル使用メモリ 177,948 KB
実行使用メモリ 42,424 KB
最終ジャッジ日時 2023-09-08 03:51:13
合計ジャッジ時間 9,227 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 679 ms
42,156 KB
testcase_04 AC 639 ms
39,780 KB
testcase_05 AC 672 ms
42,424 KB
testcase_06 AC 510 ms
30,736 KB
testcase_07 WA -
testcase_08 AC 165 ms
13,316 KB
testcase_09 AC 159 ms
12,764 KB
testcase_10 AC 5 ms
4,384 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
/*
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void in(T&t){cin>>t;}
template<class T,class... Ts>inline void in(T&t,Ts&...ts){cin>>t;in(ts...);}
template<class T>inline void out(T t){cout<<t<<endl;}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout<<t<<" ";out(ts...);}
template<typename T=int>vector<T>mv(size_t a){return vector<T>(a);}
template<typename T=int,typename... Ts>auto mv(size_t a,Ts... ts){return vector<decltype(mv<T>(ts...))>(a,mv<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill(T&t,const V&v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill(T&t,const V&v){for(auto &e:t)fill(e,v);}
constexpr long long INF = 1e18;

signed main(){
	int H,W;
	in(H,W);
	auto s = mv<string>(H);
	in(s);
	auto dist = mv(H,W);
	fill(dist,INF);
	#define P2 pair<int,pair<int,int>>
	priority_queue<P2,vector<P2>,greater<P2>>que;
	dist[0][0] = 0;
	que.push({dist[0][0],{0,0}});
	int dx[] = {0,1,0,-1};
	int dy[] = {1,0,-1,0};
	while(que.size()){
		int cost = que.top().first;
		int i = que.top().second.first;
		int j = que.top().second.second;
		que.pop();
		if(dist[i][j]!=cost)continue;
		REP(k,4){
			int ni = i + dy[k];
			int nj = j + dx[k];
			if(!IN(0,ni,H))continue;
			if(!IN(0,nj,W))continue;
			if(s[ni][nj]=='k'){
				int ncost = cost + 1 + ni + nj;
				if(CHMIN(dist[ni][nj],ncost)){
					que.push({dist[ni][nj],{ni,nj}});
				}
			}else{
				int ncost = cost + 1;
				if(CHMIN(dist[ni][nj],ncost)){
					que.push({dist[ni][nj],{ni,nj}});
				}
			}
		}
	}
	out(dist[H-1][W-1]);
}
0