QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#560610#8236. Snake Moveshabi666#WA 1013ms92088kbC++202.2kb2024-09-12 16:54:222024-09-12 16:54:22

Judging History

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

  • [2024-09-12 16:54:22]
  • 评测
  • 测评结果:WA
  • 用时:1013ms
  • 内存:92088kb
  • [2024-09-12 16:54:22]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

const int N = 3e3 + 5;
const int dx[] = {0, 0, -1, 1};
const int dy[] = {1, -1, 0, 0};

char grid[N][N];
bool vis[N][N];
unsigned int dis[N][N];
map<pair<int, int>, int> idx;

void solve() {
    memset(dis, 0x3f, sizeof dis);

    int n, m, k;
    cin >> n >> m >> k;
    int sx, sy;
    for (int i = 1; i <= k; i++) {
        int x, y;
        cin >> x >> y;
        idx[{x, y}] = i;
        if (i == 1) {
            sx = x;
            sy = y;
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> grid[i][j];
        }
    }

    auto invalid = [&](int x, int y) {
        return x < 1 || x > n || y < 1 || y > m;
    };
   priority_queue<tuple<int, int, int, int>> q;
    q.emplace(0, sx, sy, k);
    dis[sx][sy] = 0;
    while (!q.empty()) {
        auto [d, x, y, len] = q.top(); q.pop();
        if (vis[x][y])
            continue;
        vis[x][y] = true;
        for (int i = 0; i < 4; i++) {
            int xx = x + dx[i];
            int yy = y + dy[i];
            if (invalid(xx, yy) || grid[xx][yy] == '#')
                continue;
            if (idx.count({xx, yy}) && idx[{xx, yy}] <= len) {
                int d = idx[{xx, yy}];
                if (dis[xx][yy] > dis[x][y] + len - d + 1) {
                    dis[xx][yy] = dis[x][y] + len - d + 1;
                    q.emplace(-dis[xx][yy], xx, yy, max(0ll, len - d));
                }
            }
            else if (dis[xx][yy] > dis[x][y] + 1) {
                dis[xx][yy] = dis[x][y] + 1;
                q.emplace(-dis[xx][yy], xx, yy, max(0ll, len - 1));
            }
        }
    }

    unsigned int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (dis[i][j] != 0x3f3f3f3f3f3f3f3f)
                ans += dis[i][j] * dis[i][j];
        }
    }
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    // cin >> t;
    while (t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 3ms
memory: 74144kb

input:

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

output:

407

result:

ok single line: '407'

Test #4:

score: 0
Accepted
time: 920ms
memory: 92088kb

input:

3000 2900 1
1882 526
........................................................................................................#................................................................................................................................................................#................

output:

35141960580077

result:

ok single line: '35141960580077'

Test #5:

score: 0
Accepted
time: 789ms
memory: 91568kb

input:

2900 3000 1
1333 1773
.....#....#......#.#..#...#.....#.#.#.#....#...###.#..#.....##....####..#......#.......######.#........#..#......#...###.#.#..#.....#.#........##..#..#.#..#.###.#.#...#..#.##..#...#....#..#.##..#......#.######............#.#...#......#......#..#.#.#.#...#...#..##........#.###.....

output:

17464052497724

result:

ok single line: '17464052497724'

Test #6:

score: 0
Accepted
time: 72ms
memory: 85660kb

input:

3000 3000 1
2755 225
##..#.##.....####..#...###.#.##.#.##.#......###.#####..#..####....#.#.####..##..##.#...#...##..#.#.##..#....##.#...#.....##.#...##.##.##..##..#######.####.####......##.##.#....#..#.....#..##.#.#...#.####..##.#..#...###..###.#.#...##.#.....###.####......##...#...#....#.#...#.#.#....

output:

255915

result:

ok single line: '255915'

Test #7:

score: 0
Accepted
time: 70ms
memory: 85696kb

input:

3000 2900 1
878 738
#.##.##..##.#.#.###.#...###.####.#.###.####.##.#.#####.#.####..#.#.###.###..####.####...###..####.########..##..#####.#....#####.#.#########..#.###.##.##.#####.#####.#.##..###..##.#####.#.############..##.###.##.##..########.#.###..###...######.####...#######.###.###..####.######...

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 1013ms
memory: 91656kb

input:

2900 3000 10
2883 1758
2883 1759
2883 1760
2883 1761
2883 1762
2884 1762
2884 1763
2883 1763
2882 1763
2882 1764
........................................................#............................#........................................................................................................

output:

49803365625286

result:

ok single line: '49803365625286'

Test #9:

score: 0
Accepted
time: 918ms
memory: 91928kb

input:

3000 3000 10
2015 1932
2015 1931
2015 1930
2015 1929
2016 1929
2017 1929
2018 1929
2018 1928
2018 1927
2017 1927
#...#...#..#.........#.......#####....#...###..#..###..###....##.....#..#..#...#.....##...##.#..#..##.###.........##.....#....#..##.##.#.#.##.#.#.#.....#....##.##.#..##....#....#...#.#......

output:

22509095749285

result:

ok single line: '22509095749285'

Test #10:

score: -100
Wrong Answer
time: 76ms
memory: 85592kb

input:

3000 2900 10
326 1781
325 1781
325 1782
325 1783
325 1784
324 1784
324 1783
323 1783
323 1782
324 1782
##.#....#.###.######..#.#.....##.#.##..####.####.##..#..#.###.#####....##.#.##.#..###..##.###.##.#####.###..##.#..##..##.#..##.#.#.##...##..#.##.##........#..#..###.##.###.####.#..########.##.....#...

output:

41879

result:

wrong answer 1st lines differ - expected: '40571', found: '41879'