QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#728348 | #8236. Snake Move | veg# | WA | 271ms | 25756kb | C++14 | 1.1kb | 2024-11-09 15:00:55 | 2024-11-09 15:00:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
struct Point {
int x, y;
Point(int x = 0, int y = 0) : x(x), y(y) {}
} a[100005];
bool vis[3005][3005], flag[3005][3005];
char c[3005][3005];
int dir[4][2] = {1, 0, -1, 0, 0, -1, 0, 1};
int n, m, K;
int main() {
scanf("%d%d%d", &n, &m, &K);
for (int i = 1; i <= K; ++i) {
scanf("%d%d", &a[i].x, &a[i].y);
flag[a[i].x][a[i].y] = 1;
}
for (int i = 1; i <= n; ++i)
scanf("%s", c[i] + 1);
queue<Point> q;
vis[a[1].x][a[1].y] = 1;
unsigned long long step = 0;
unsigned long long ans = 0;
for (step = 1; step <= 2 * n * m; ++step) {
if (step <= K) {
flag[a[K - step + 1].x][a[K - step + 1].y] = 0;
q.push(a[1]);
}
int sz = q.size();
for (int i = 1; i <= sz; ++i) {
auto tmp = q.front();
q.pop();
int x = tmp.x, y = tmp.y;
for (int j = 0; j < 4; ++j) {
int nx = x + dir[j][0], ny = y + dir[j][1];
if (nx >= 1 && nx <= n && ny >= 1 && ny <= m &&
!vis[nx][ny] && c[nx][ny] == '.' && !flag[nx][ny]) {
vis[nx][ny] = 1;
q.push(Point{nx, ny});
ans = ans + step * step;
}
}
}
}
cout << ans << endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 8552kb
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: 8844kb
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: 1ms
memory: 10376kb
input:
5 5 3 1 2 1 1 2 1 ..... .###. .#.#. .###. .....
output:
407
result:
ok single line: '407'
Test #4:
score: 0
Accepted
time: 147ms
memory: 24700kb
input:
3000 2900 1 1882 526 ........................................................................................................#................................................................................................................................................................#................
output:
35141960580077
result:
ok single line: '35141960580077'
Test #5:
score: 0
Accepted
time: 270ms
memory: 24628kb
input:
2900 3000 1 1333 1773 .....#....#......#.#..#...#.....#.#.#.#....#...###.#..#.....##....####..#......#.......######.#........#..#......#...###.#.#..#.....#.#........##..#..#.#..#.###.#.#...#..#.##..#...#....#..#.##..#......#.######............#.#...#......#......#..#.#.#.#...#...#..##........#.###.....
output:
17464052497724
result:
ok single line: '17464052497724'
Test #6:
score: 0
Accepted
time: 51ms
memory: 15704kb
input:
3000 3000 1 2755 225 ##..#.##.....####..#...###.#.##.#.##.#......###.#####..#..####....#.#.####..##..##.#...#...##..#.#.##..#....##.#...#.....##.#...##.##.##..##..#######.####.####......##.##.#....#..#.....#..##.#.#...#.####..##.#..#...###..###.#.#...##.#.....###.####......##...#...#....#.#...#.#.#....
output:
255915
result:
ok single line: '255915'
Test #7:
score: 0
Accepted
time: 50ms
memory: 20592kb
input:
3000 2900 1 878 738 #.##.##..##.#.#.###.#...###.####.#.###.####.##.#.#####.#.####..#.#.###.###..####.####...###..####.########..##..#####.#....#####.#.#########..#.###.##.##.#####.#####.#.##..###..##.#####.#.############..##.###.##.##..########.#.###..###...######.####...#######.###.###..####.######...
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 154ms
memory: 24784kb
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: 271ms
memory: 25756kb
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: 33ms
memory: 18604kb
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:
41915
result:
wrong answer 1st lines differ - expected: '40571', found: '41915'