QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#844686 | #8236. Snake Move | axujls | WA | 0ms | 3544kb | C++14 | 1.2kb | 2025-01-06 10:03:03 | 2025-01-06 10:03:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};
int main() {
int n, m, k; cin >> n >> m >> k;
vector<pair<int, int>> coords(k + 5);
vector<vector<int>> dp(n + 5, vector<int>(m + 5));
for(int i = 1; i <= k; i++){
cin >> coords[i].first >> coords[i].second;
dp[coords[i].first][coords[i].second] += (k - i);
}
vector<vector<char>>cgrid(n + 5, vector<char>(m+5));
for(int i = 1; i <= n; i++){
string row; cin >> row;
for(int j = 1; j <= m; j++){
cgrid[i][j] = row[j-1];
}
}
int d[n+5][m+5];
memset(d, -1, sizeof d);
vector<pair<int, int>> e[(n+1)*(n+1)];
d[coords[1].first][coords[1].second] = 0;
e[0].emplace_back(coords[1].first, coords[1].second);
unsigned long long ans = 0;
for(int i = 0; i < n * n - 1; i++){
for(auto[x, y] : e[i]){
ans += i * 1LL * i;
for(int j = 0; j < 4; j++){
int xx = x + DX[j]; int yy = y + DY[j];
if(xx < 1 || yy < 1 || xx > n || yy > m || cgrid[xx][yy] == '#' || d[xx][yy] != -1){
continue;
}
e[d[xx][yy] = max(i, dp[xx][yy]) + 1].emplace_back(xx, yy);
}
}
}
cout << ans << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3496kb
input:
4 5 5 3 5 3 4 3 3 3 2 4 2 ..... ..... ..... .....
output:
293
result:
ok single line: '293'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3544kb
input:
2 2 4 1 1 1 2 2 2 2 1 .. ..
output:
5
result:
wrong answer 1st lines differ - expected: '14', found: '5'