QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#700057#9224. Express EvictionRico64WA 10ms4140kbC++232.3kb2024-11-02 11:47:322024-11-02 11:47:32

Judging History

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

  • [2024-11-02 11:47:32]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:4140kb
  • [2024-11-02 11:47:32]
  • 提交

answer

#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int xl, yl;
bool grid[50][50];

int get(int x, int y) {
    if (x < 0 || x >= xl || y < 0 || y >= yl) 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 - get(x1, y1) - get(x2, y2), {{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;
    pq.push({-get(0, 0), {{0, 0}, vector<vector<bool>>(xl, vector<bool>(yl))}});
    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: 1ms
memory: 3844kb

input:

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

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: -100
Wrong Answer
time: 10ms
memory: 4140kb

input:

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

output:

12

result:

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