結果

問題 No.971 いたずらっ子
ユーザー akun0716akun0716
提出日時 2020-10-29 22:40:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,115 bytes
コンパイル時間 947 ms
コンパイル使用メモリ 91,264 KB
実行使用メモリ 70,604 KB
最終ジャッジ日時 2023-09-29 04:10:50
合計ジャッジ時間 4,912 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 563 ms
70,604 KB
testcase_06 AC 433 ms
64,028 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 4 ms
6,012 KB
testcase_11 AC 2 ms
5,656 KB
testcase_12 AC 2 ms
5,520 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
5,448 KB
testcase_18 AC 2 ms
5,464 KB
testcase_19 AC 2 ms
5,716 KB
testcase_20 AC 2 ms
5,676 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 3 ms
5,576 KB
testcase_24 AC 2 ms
5,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair <int, pair<int, int> >pii;
typedef pair<int, int>P;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;

int H, W;
VS S(2010);
int dx[] = { 0,1 };
int dy[] = { 1,0 };
int d[2010][2010];
int cnt[2010][2010];

bool is_in(int x, int y) {
	return (0 <= x && 0 <= y && x < H&&y < W);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> H >> W;
	REP(i, H)cin >> S[i];
	priority_queue<pii, vector<pii>, greater<pii> >Q;
	REP(i, H)REP(j, W)d[i][j] = INF;
	Q.push(make_pair(0, P(0, 0)));
	d[0][0] = 0;
	while (!Q.empty()) {
		int x = Q.top().second.first;
		int y = Q.top().second.second;
		int t = Q.top().first;
		Q.pop();
		if (d[x][y] < t)continue;

		REP(k, 2) {
			int tox = x + dx[k], toy = y + dy[k];
			if (!is_in(tox, toy))continue;
			bool F = 0;
			int tmp = d[x][y] + 1;
			if (S[tox][toy] == 'k') {
				tmp *= 2;
				tmp -= cnt[x][y];
				F = 1;
			}
			if (d[tox][toy] > tmp) {
				d[tox][toy] = tmp;
				cnt[tox][toy] += cnt[x][y] + F;
				Q.push(make_pair(tmp, P(tox, toy)));
			}
		}
	}
	cout << d[H - 1][W - 1] << endl;



	return 0;
}

0