QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#843740 | #8236. Snake Move | AksLolCoding | WA | 0ms | 3560kb | C++17 | 1.2kb | 2025-01-05 00:18:23 | 2025-01-05 00:18:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int dx[4]={0,0,1,-1}, dy[4]={-1,1,0,0};
void solve() {
int n, m, k, hx, hy;
cin >> n >> m >> k >> hx >> hy;
int b[n][m];
memset(b, 0, n*m*sizeof(int));
b[--hx][--hy] = --k;
while (k) {
int x, y;
cin >> x >> y;
b[--x][--y] = --k;
}
char grid[n][m];
for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> grid[i][j];
for (int ix = 0; ix < n; ix++) {
}
// solve
vector<array<int, 2>> v[n*m];
int f[n][m]; // distance array
memset(f, -1, n*m*sizeof(int));
ll ans;
v[f[hx][hy] = 0].push_back({hx, hy});
for (int d = 0; d < n*m; d++) {
for (auto &[x, y]: v[d]) {
ans += (ll)d*d;
for (int i: {0, 1, 2, 3}) {
int nx = x+dx[i], ny = y+dy[i];
if (nx < 0 || ny < 0 || nx>=n || ny>=m || grid[nx][ny] == '#' || f[nx][ny] != -1) continue;
v[f[nx][ny] = max(b[nx][ny],d)+1].push_back({nx, ny});
}
}
}
// ans
cout << ans << '\n';
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3560kb
input:
4 5 5 3 5 3 4 3 3 3 2 4 2 ..... ..... ..... .....
output:
33061
result:
wrong answer 1st lines differ - expected: '293', found: '33061'