QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#688228 | #5582. Chocolate Chip Fabrication | Tenshi# | WA | 0ms | 3764kb | C++23 | 1.3kb | 2024-10-30 01:14:12 | 2024-10-30 01:14:13 |
Judging History
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;
}
詳細信息
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'