結果

問題 No.971 いたずらっ子
ユーザー okok
提出日時 2020-01-17 21:55:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 788 ms / 2,000 ms
コード長 1,864 bytes
コンパイル時間 996 ms
コンパイル使用メモリ 98,744 KB
実行使用メモリ 70,388 KB
最終ジャッジ日時 2023-08-07 07:53:59
合計ジャッジ時間 7,882 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 788 ms
70,348 KB
testcase_01 AC 787 ms
70,300 KB
testcase_02 AC 575 ms
53,492 KB
testcase_03 AC 635 ms
70,256 KB
testcase_04 AC 596 ms
66,308 KB
testcase_05 AC 639 ms
70,388 KB
testcase_06 AC 483 ms
55,152 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 151 ms
21,032 KB
testcase_09 AC 144 ms
20,212 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define f first
#define s second

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int dx[2] = {1,0};
	int dy[2] = {0,1};
	int H, W;
	vector<string> a;
	vector<vector<int>> dis, dis2;
	priority_queue<pair<pair<int,int>,pair<int,int>>, vector<pair<pair<int,int>,pair<int,int>>>, greater<pair<pair<int,int>,pair<int,int>>>> Q;
	
	cin>>H>>W;
	
	a.resize(H);
	dis.resize(H, vector<int>(W, INF));
	dis2.resize(H, vector<int>(W, INF));
	
	for(int i = 0; i < H; i++){
		cin>>a[i];
	}
	
	Q.push({{0,0},{0,0}});
	dis[0][0] = 0;
	dis2[0][0] = 0;
	
	while(!Q.empty()){
		pair<pair<int,int>,pair<int,int>> P = Q.top(); Q.pop();
		int d1 = P.first.first, d2 = P.first.second;
		int y = P.second.first, x = P.second.second;
		
		if(dis[y][x] < d1) continue;
		
		if(y == H-1 && x == W-1) break;
		
		for(int i = 0; i < 2; i++){
			int ny = y + dy[i], nx = x + dx[i];
			// cout<<"y = "<<y<<" x = "<<x<<endl;

			// cout<<"ny = "<<ny<<" nx = "<<nx<<endl;
			
			if(ny >= H || ny < 0 || nx >= W || nx < 0) continue;
			
			int td = 0;
			
			if(a[ny][nx] == 'k') {
				// cout<<"<><> "<<endl;
				td = d1 + ny + nx + 1;
			} else {
				td = d1 + 1;
			}
			
			// cout<<"td = "<<td<<" dis "<<dis[ny][nx]<<endl;
			
			if(dis[ny][nx] > td) {
				dis[ny][nx] = td;
				Q.push({{td,0},{ny,nx}});
			}
		}
		// cout<<endl;
	}
	
	// cout<<dis[0][0]<<endl;
	// cout<<dis[0][1]<<endl;
	// cout<<dis[1][0]<<endl;
	// cout<<dis[1][1]<<endl;
	
	cout<<dis[H-1][W-1]<<endl;
	
	return 0;
}
0