QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#655167#9224. Express Evictiongreen_gold_dogWA 0ms3868kbC++202.7kb2024-10-19 01:05:112024-10-19 01:05:12

Judging History

你现在查看的是最新测评结果

  • [2024-10-19 01:05:12]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3868kb
  • [2024-10-19 01:05:11]
  • 提交

answer

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,popcnt,mmx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;
typedef complex<double> cd;

constexpr ll INF64 = 9'000'000'000'000'000'000, INF32 = 2'000'000'000, MOD = 1'000'000'007;
constexpr db PI = acos(-1);
constexpr bool IS_FILE = false, IS_TEST_CASES = false;

random_device rd;
mt19937 rnd32(rd());
mt19937_64 rnd64(rd());

template<typename T>
bool assign_max(T& a, T b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

template<typename T>
bool assign_min(T& a, T b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

template<typename T>
T square(T a) {
	return a * a;
}

template<>
struct std::hash<pair<ll, ll>> {
	ll operator() (pair<ll, ll> p) const {
		return ((__int128)p.first * MOD + p.second) % INF64;
	}
};

void solve() {
	ll h, w;
	cin >> h >> w;
	vector<vector<char>> arr(h, vector<char>(w));
	for (ll i = 0; i < h; i++) {
		for (ll j = 0; j < w; j++) {
			cin >> arr[i][j];
		}
	}
	vector<vector<ll>> dp(h + 1, vector<ll>(w + 1, INF32));
	dp[0][0] = arr[0][0] == '#';
	priority_queue<tuple<ll, ll, ll>, vector<tuple<ll, ll, ll>>, greater<tuple<ll, ll, ll>>> pq;
	pq.emplace(dp[0][0], 0, 0);
	while (!pq.empty()) {
		auto[d, x, y] = pq.top();
		pq.pop();
		if (dp[x][y] != d) {
			continue;
		}
		if (x < h) {
			ll nans = d;
			if (x + 1 < h) {
				if (y > 0) {
					nans += arr[x + 1][y - 1] == '#';
				}
				if (y < w) {
					nans += arr[x + 1][y] == '#';
				}
			}
			if (assign_min(dp[x + 1][y], nans)) {
				pq.emplace(nans, x + 1, y);
			}
		}
		if (x > 0) {
			ll nans = d;
			if (x - 1 > 0) {
				if (y > 0) {
					nans += arr[x - 1][y - 1] == '#';
				}
				if (y < w) {
					nans += arr[x - 1][y] == '#';
				}
			}
			if (assign_min(dp[x - 1][y], nans)) {
				pq.emplace(nans, x - 1, y);
			}
		}
		if (y < w) {
			ll nans = d;
			if (y + 1 < w) {
				if (x > 0) {
					nans += arr[x - 1][y + 1] == '#';
				}
				if (x < h) {
					nans += arr[x][y  + 1] == '#';
				}
			}
			if (assign_min(dp[x][y + 1], nans)) {
				pq.emplace(nans, x, y + 1);
			}
		}
		if (y > 0) {
			ll nans = d;
			if (y - 1 > 0) {
				if (x > 0) {
					nans += arr[x - 1][y - 1] == '#';
				}
				if (x < h) {
					nans += arr[x][y - 1] == '#';
				}
			}
			if (assign_min(dp[x][y - 1], nans)) {
				pq.emplace(nans, x, y - 1);
			}
		}
	}
	cout << dp[h][w] << '\n';
}

int main() {
	if (IS_FILE) {
		freopen("", "r", stdin);
		freopen("", "w", stdout);
	}
    	ios_base::sync_with_stdio(false);
    	cin.tie(0);
    	cout.tie(0);
	ll t = 1;
	if (IS_TEST_CASES) {
		cin >> t;
	}
	for (ll i = 0; i < t; i++) {
		solve();
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3868kb

input:

4 6
.##...
.#....
##....
....#.

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3852kb

input:

20 30
...###########################
#..###########################
...###########################
...###########################
.#############################
...###########################
...###########################
#..###########################
...###########################
..#...............

output:

10

result:

wrong answer 1st numbers differ - expected: '11', found: '10'