QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#655174 | #9224. Express Eviction | real_sigma_team# | WA | 0ms | 3868kb | C++20 | 2.7kb | 2024-10-19 01:09:44 | 2024-10-19 01:09:44 |
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(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 - 2][y - 1] == '#';
}
if (y < w) {
nans += arr[x - 2][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 - 2] == '#';
}
if (x < h) {
nans += arr[x][y - 2] == '#';
}
}
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();
}
}
Details
Tip: Click on the bar to expand more detailed information
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: 3848kb
input:
20 30 ...########################### #..########################### ...########################### ...########################### .############################# ...########################### ...########################### #..########################### ...########################### ..#...............
output:
12
result:
wrong answer 1st numbers differ - expected: '11', found: '12'