QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#688228#5582. Chocolate Chip FabricationTenshi#WA 0ms3764kbC++231.3kb2024-10-30 01:14:122024-10-30 01:14:13

Judging History

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

  • [2024-10-30 01:14:13]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3764kb
  • [2024-10-30 01:14:12]
  • 提交

answer

#include <bits/stdc++.h>
#include <iostream>
#include <queue>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

#define sz(x) (long long)(x).size()

int main() {
    int n, m; cin >> n >> m;
    vector<vector<bool>> grid(n+2, vector<bool>(m+2, false));
    rep(i, n) {
        string s; cin >> s;
        rep (j, m) {
            if (s[j]=='X') grid[i+1][j+1] = true;
        }
    }

    priority_queue<pair<int, pair<int, int>>> pq;

    pq.push({0, {0, 0}});

    vector<vector<int>> dist(n+2, vector<int>(m+2, -1));


    while (sz(pq)) {
        pair<int, pair<int, int>> data = pq.top();pq.pop();

        int depth = -data.first;
        int r = data.second.first;
        int c = data.second.second;
        if (dist[r][c]!=-1) continue;
        dist[r][c] = depth;
        pair<int, int> disp[4] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
        for (pair<int, int> off : disp) {
            if (r + off.first < 0 or r+off.first >= n+2 or c + off.second < 0 or c+off.second >= n+2) continue;
            pq.push({-depth - (grid[r + off.first][c + off.second] ? 1:0), {r+off.first, c+off.second}});
        }
    }
    int mx = 0;
    rep(i, n+2) {rep(j, m+2) {mx = max(mx, dist[i][j]);}}
    cout << mx << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 5
-X-X-
XXXXX
XXXXX
-XXX-
--X--

output:

2

result:

ok single line: '2'

Test #2:

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

input:

4 5
--XXX
--X-X
X-XXX
XX---

output:

2

result:

wrong answer 1st lines differ - expected: '1', found: '2'