QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#700071 | #9224. Express Eviction | Rico64 | WA | 58ms | 4852kb | C++23 | 2.4kb | 2024-11-02 11:51:48 | 2024-11-02 11:51:48 |
Judging History
answer
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int xl, yl;
bool grid[50][50];
int get2(int x, int y, vector<vector<bool>>& g) {
if (x < 0 || x >= xl || y < 0 || y >= yl || g[x][y]) return 0;
return grid[x][y];
}
bool get(int x, int y, vector<vector<bool>>& g) {
if (x < 0 || x >= xl || y < 0 || y >= yl) return false;
return g[x][y];
}
void set(int x, int y, vector<vector<bool>>& g, bool v) {
if (x < 0 || x >= xl || y < 0 || y >= yl) return;
g[x][y] = v;
}
pair<int,pair<pair<int, int>, vector<vector<bool>>>> pu(int nx, int ny, int x1, int y1, int x2, int y2, vector<vector<bool>>& ctrav, vector<vector<bool>>& g, int cost) {
set(x1, y1, g, true);
set(x2, y2, g, true);
pair<int,pair<pair<int, int>, vector<vector<bool>>>> res = {cost - get2(x1, y1, ctrav) - get2(x2, y2, ctrav), {{nx, ny}, g}};
set(x1, y1, g, get(x1, y1, ctrav));
set(x2, y2, g, get(x2, y2, ctrav));
return res;
}
int main() {
cin >> xl >> yl;
for (int x = 0; x < xl; ++x) {
string s;
cin >> s;
for (int y = 0; y < yl; ++y) {
grid[x][y] = s[y] == '#';
}
}
priority_queue<pair<int,pair<pair<int, int>, vector<vector<bool>>>>> pq;
auto k = vector<vector<bool>>(xl, vector<bool>(yl, false));
pq.push({-get2(0, 0, k), {{0, 0}, vector<vector<bool>>(xl, vector<bool>(yl, false))}});
bool trav[xl + 1][yl + 1];
for (int x = 0; x <= xl; ++x) fill(trav[x], trav[x] + (yl + 1), false);
while (!pq.empty()) {
pair<int,pair<pair<int, int>, vector<vector<bool>>>> cur = pq.top(); pq.pop();
int x = cur.second.first.first;
int y = cur.second.first.second;
int cost = cur.first;
vector<vector<bool>> ctrav = cur.second.second;
if (x < 0 || x >= xl + 1 || y < 0 || y >= yl + 1) continue;
// cout << x << ' ' << y << ' ' << -cost << endl;
if (trav[x][y]) continue;
trav[x][y] = true;
if (x == xl && y == yl) {
cout << -cost << endl;
return 0;
}
vector<vector<bool>> g = ctrav;
pq.push(pu(x + 1, y, x + 1, y, x + 1, y - 1, ctrav, g, cost));
pq.push(pu(x, y + 1, x, y + 1, x - 1, y + 1, ctrav, g, cost));
pq.push(pu(x - 1, y, x - 2, y, x - 2, y - 1, ctrav, g, cost));
pq.push(pu(x, y - 1, x, y - 2, x - 1, y - 2, ctrav, g, cost));
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3684kb
input:
4 6 .##... .#.... ##.... ....#.
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 10ms
memory: 3912kb
input:
20 30 ...########################### #..########################### ...########################### ...########################### .############################# ...########################### ...########################### #..########################### ...########################### ..#...............
output:
11
result:
ok 1 number(s): "11"
Test #3:
score: -100
Wrong Answer
time: 58ms
memory: 4852kb
input:
35 35 ....###########...#########........ ##..#######################..#####. ....#######################..#####. ...#.....##################..#####. .##......##################.....##. .##..##..#############.....#....##. .....##..#############......##..##. ....#....#############..##..##..##. ####.....
output:
19
result:
wrong answer 1st numbers differ - expected: '16', found: '19'