結果

問題 No.971 いたずらっ子
ユーザー ransewhaleransewhale
提出日時 2020-01-17 21:44:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,315 bytes
コンパイル時間 1,825 ms
コンパイル使用メモリ 173,400 KB
実行使用メモリ 75,136 KB
最終ジャッジ日時 2023-09-08 02:11:35
合計ジャッジ時間 10,141 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 774 ms
74,792 KB
testcase_04 AC 727 ms
74,448 KB
testcase_05 AC 776 ms
74,968 KB
testcase_06 AC 569 ms
70,612 KB
testcase_07 WA -
testcase_08 AC 196 ms
69,164 KB
testcase_09 AC 188 ms
69,096 KB
testcase_10 AC 22 ms
67,404 KB
testcase_11 AC 19 ms
67,184 KB
testcase_12 AC 20 ms
67,096 KB
testcase_13 AC 19 ms
67,192 KB
testcase_14 WA -
testcase_15 AC 19 ms
67,192 KB
testcase_16 AC 19 ms
67,176 KB
testcase_17 AC 19 ms
67,180 KB
testcase_18 AC 19 ms
67,200 KB
testcase_19 AC 19 ms
67,232 KB
testcase_20 AC 19 ms
67,304 KB
testcase_21 AC 19 ms
67,116 KB
testcase_22 AC 19 ms
67,184 KB
testcase_23 AC 19 ms
67,272 KB
testcase_24 AC 19 ms
67,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PL;
typedef pair<int, int> P;
typedef pair<PL, P> E;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int h,w;
PL dist[2020][2020];
string a[2020];

bool check(int i, int j){
	return (0<=i&&i<h&&0<=j&&j<w);
}

priority_queue<E, vector<E>, greater<E> > pq;

int main(void){
	int dx[4]={-1,0,0,1},dy[4]={0,-1,1,0},i,j,k,x,y;
	ll c,e; PL tmp;
	fill(dist[0],dist[2020],PL(INFLL,INFLL));
	dist[0][0] = PL(0ll,0ll); pq.push(E(dist[0][0],P(0,0)));
	cin >> h >> w;
	for(i=0; i<h; ++i){
		cin >> a[i];
	}
	while(!pq.empty()){
		i = pq.top().second.first;
		j = pq.top().second.second;
		c = pq.top().first.first;
		e = pq.top().first.second;
		pq.pop();
		if(dist[i][j] < PL(c,e)){
			continue;
		}
		for(k=0; k<4; ++k){
			x = i + dx[k];
			y = j + dy[k];
			if(!check(x,y)){
				continue;
			}
			tmp = PL(c+1,e+1);
			if(a[x][y]=='k'){
				tmp.first += tmp.second;
			}
			if(dist[x][y] > tmp){
				dist[x][y] = tmp;
				pq.push(E(dist[x][y],P(x,y)));
			}
		}
	}
	cout << dist[h-1][w-1].first << endl;
	return 0;
}
0