結果

問題 No.971 いたずらっ子
ユーザー ransewhaleransewhale
提出日時 2020-01-17 21:48:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 950 ms / 2,000 ms
コード長 1,316 bytes
コンパイル時間 1,832 ms
コンパイル使用メモリ 172,732 KB
実行使用メモリ 75,068 KB
最終ジャッジ日時 2024-04-25 01:59:13
合計ジャッジ時間 10,978 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 950 ms
75,008 KB
testcase_01 AC 948 ms
75,008 KB
testcase_02 AC 697 ms
71,148 KB
testcase_03 AC 850 ms
75,008 KB
testcase_04 AC 803 ms
74,476 KB
testcase_05 AC 851 ms
75,068 KB
testcase_06 AC 640 ms
70,656 KB
testcase_07 AC 46 ms
67,456 KB
testcase_08 AC 232 ms
69,248 KB
testcase_09 AC 227 ms
69,248 KB
testcase_10 AC 42 ms
67,456 KB
testcase_11 AC 38 ms
67,328 KB
testcase_12 AC 36 ms
67,456 KB
testcase_13 AC 37 ms
67,364 KB
testcase_14 AC 38 ms
67,328 KB
testcase_15 AC 39 ms
67,316 KB
testcase_16 AC 38 ms
67,456 KB
testcase_17 AC 37 ms
67,360 KB
testcase_18 AC 38 ms
67,244 KB
testcase_19 AC 40 ms
67,388 KB
testcase_20 AC 37 ms
67,436 KB
testcase_21 AC 39 ms
67,328 KB
testcase_22 AC 37 ms
67,328 KB
testcase_23 AC 38 ms
67,456 KB
testcase_24 AC 39 ms
67,448 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