QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#655164 | #9224. Express Eviction | real_sigma_team# | WA | 1ms | 3552kb | C++20 | 2.7kb | 2024-10-19 01:03:25 | 2024-10-19 01:03:25 |
Judging History
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(0, 0, dp[0][0]);
while (!pq.empty()) {
auto[x, y, d] = 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(x + 1, y, nans);
}
}
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(x - 1, y, nans);
}
}
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(x, y + 1, nans);
}
}
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(x, y - 1, nans);
}
}
}
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: 3536kb
input:
4 6 .##... .#.... ##.... ....#.
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3552kb
input:
20 30 ...########################### #..########################### ...########################### ...########################### .############################# ...########################### ...########################### #..########################### ...########################### ..#...............
output:
10
result:
wrong answer 1st numbers differ - expected: '11', found: '10'