結果

問題 No.971 いたずらっ子
ユーザー ransewhaleransewhale
提出日時 2020-01-17 21:48:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 908 ms / 2,000 ms
コード長 1,316 bytes
コンパイル時間 1,544 ms
コンパイル使用メモリ 175,408 KB
実行使用メモリ 74,960 KB
最終ジャッジ日時 2023-08-07 07:53:00
合計ジャッジ時間 9,946 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 906 ms
74,804 KB
testcase_01 AC 908 ms
74,960 KB
testcase_02 AC 660 ms
71,092 KB
testcase_03 AC 775 ms
74,848 KB
testcase_04 AC 729 ms
74,516 KB
testcase_05 AC 773 ms
74,856 KB
testcase_06 AC 573 ms
70,644 KB
testcase_07 AC 25 ms
67,208 KB
testcase_08 AC 194 ms
69,208 KB
testcase_09 AC 187 ms
69,160 KB
testcase_10 AC 23 ms
67,280 KB
testcase_11 AC 20 ms
67,276 KB
testcase_12 AC 19 ms
67,276 KB
testcase_13 AC 20 ms
67,196 KB
testcase_14 AC 21 ms
67,180 KB
testcase_15 AC 19 ms
67,280 KB
testcase_16 AC 19 ms
67,120 KB
testcase_17 AC 20 ms
67,128 KB
testcase_18 AC 19 ms
67,288 KB
testcase_19 AC 20 ms
67,180 KB
testcase_20 AC 19 ms
67,120 KB
testcase_21 AC 19 ms
67,216 KB
testcase_22 AC 19 ms
67,236 KB
testcase_23 AC 19 ms
67,272 KB
testcase_24 AC 20 ms
67,272 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()){
		c = pq.top().first.first;
		e = pq.top().first.second;
		i = pq.top().second.first;
		j = pq.top().second.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.second += tmp.first;
			}
			if(dist[x][y] > tmp){
				dist[x][y] = tmp;
				pq.push(E(dist[x][y],P(x,y)));
			}
		}
	}
	cout << dist[h-1][w-1].second << endl;
	return 0;
}
0