QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#844709 | #8236. Snake Move | axujls | RE | 404ms | 372308kb | C++14 | 1.1kb | 2025-01-06 10:18:54 | 2025-01-06 10:18:55 |
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 + 1);
vector<vector<int>> dp(n + 1, vector<int>(m + 1));
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 + 1, vector<char>(m+1));
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+1][m+1];
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*m; 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";
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
input:
4 5 5 3 5 3 4 3 3 3 2 4 2 ..... ..... ..... .....
output:
293
result:
ok single line: '293'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
2 2 4 1 1 1 2 2 2 2 1 .. ..
output:
14
result:
ok single line: '14'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
5 5 3 1 2 1 1 2 1 ..... .###. .#.#. .###. .....
output:
407
result:
ok single line: '407'
Test #4:
score: 0
Accepted
time: 404ms
memory: 372308kb
input:
3000 2900 1 1882 526 ........................................................................................................#................................................................................................................................................................#................
output:
35141960580077
result:
ok single line: '35141960580077'
Test #5:
score: -100
Runtime Error
input:
2900 3000 1 1333 1773 .....#....#......#.#..#...#.....#.#.#.#....#...###.#..#.....##....####..#......#.......######.#........#..#......#...###.#.#..#.....#.#........##..#..#.#..#.###.#.#...#..#.##..#...#....#..#.##..#......#.######............#.#...#......#......#..#.#.#.#...#...#..##........#.###.....