QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#844676#8236. Snake MoveaxujlsRE 408ms372832kbC++141.4kb2025-01-06 09:50:142025-01-06 09:50:15

Judging History

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

  • [2025-01-06 09:50:15]
  • 评测
  • 测评结果:RE
  • 用时:408ms
  • 内存:372832kb
  • [2025-01-06 09:50:14]
  • 提交

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);
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
    for(int i = 0; i < k; i++) {
        cin >> coords[i].first >> coords[i].second;
        dp[coords[i].first][coords[i].second] = (k - i - 1);
    }
    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];
        }
    }
    vector<vector<int>> d(n + 1, vector<int>(m + 1, -1));
    vector<pair<int, int>> e[(n + 1) * (n + 1)];
    d[coords[0].first][coords[0].second] = 0;
    e[0].emplace_back(coords[0].first, coords[0].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], yy = y + DY[j];
                if(xx < 1 || yy < 1 || xx > n || yy > m || cgrid[xx][yy] == '#' || d[xx][yy] != -1)
                    continue;
                d[xx][yy] = max(i, dp[xx][yy]) + 1;
                e[d[xx][yy]].emplace_back(xx, yy);
            }
        }
    }
    cout << ans << "\n";
}

详细

Test #1:

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

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: 3636kb

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: 3592kb

input:

5 5 3
1 2
1 1
2 1
.....
.###.
.#.#.
.###.
.....

output:

407

result:

ok single line: '407'

Test #4:

score: 0
Accepted
time: 408ms
memory: 372832kb

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
.....#....#......#.#..#...#.....#.#.#.#....#...###.#..#.....##....####..#......#.......######.#........#..#......#...###.#.#..#.....#.#........##..#..#.#..#.###.#.#...#..#.##..#...#....#..#.##..#......#.######............#.#...#......#......#..#.#.#.#...#...#..##........#.###.....

output:


result: