QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#345156 | #8236. Snake Move | oscaryang# | WA | 1469ms | 157520kb | C++20 | 2.0kb | 2024-03-06 11:40:07 | 2024-03-06 11:40:07 |
Judging History
answer
#include<bits/stdc++.h>
#define ull unsigned long long
#define vc vector
#define pb emplace_back
#define pii pair<int, int>
#define mkp make_pair
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define lep(i, a, b) for(int i = (a); i >= (b); --i)
using namespace std;
inline int read() {
int x = 0, w = 0; char ch = getchar(); while(!isdigit(ch)) w |= (ch == '-'), ch = getchar();
while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return w ? -x : x;
}
const int N = 3005, inf = 1e9;
const int dx[5] = {1, -1, 0, 0}, dy[5] = {0, 0, 1, -1};
struct node { int x, y, z, d; bool friend operator < (node A, node B) { return A.d > B.d; } };
int n, m, k, sx, sy, a[N][N], f[N][N][2], vis[N][N][2];
ull ans;
char Map[N][N];
inline int ok(int x, int y) { return x > 0 && x <= n && y > 0 && y <= m && Map[x][y] == '.'; }
inline void dij() {
priority_queue<node> Q; Q.push(node{sx, sy, 0, f[sx][sy][0] = 0});
while(!Q.empty()) {
auto [x, y, z, d] = Q.top(); Q.pop();
if(vis[x][y][z]) continue; vis[x][y][z] = 1;
if(z) {
for(int i = 0, nx = x + dx[0], ny = y + dy[0]; i < 4; i++, nx = x + dx[i], ny = y + dy[i])
if(ok(nx, ny) && f[nx][ny][1] > d + 1) Q.push(node{nx, ny, 1, f[nx][ny][1] = d + 1});
}
else {
for(int i = 0, nx = x + dx[0], ny = y + dy[0]; i < 4; i++, nx = x + dx[i], ny = y + dy[i]) if(ok(nx, ny)) {
if(a[nx][ny] && k - a[nx][ny] >= d + 1) {
int nd = k - a[nx][ny] + 1;
if(nd < f[nx][ny][1]) Q.push(node{nx, ny, 1, f[nx][ny][1] = nd});
}
else if(d + 1 < f[nx][ny][0]) Q.push(node{nx, ny, 0, f[nx][ny][0] = d + 1});
}
}
}
}
signed main() {
n = read(); m = read(); k = read();
for(int i = 1, u, v; i <= k; i++) {
u = read(), v = read(), a[u][v] = i;
if(i == 1) sx = u, sy = v;
}
rep(i, 1, n) scanf("%s", Map[i] + 1);
rep(i, 1, n) rep(j, 1, m) rep(k, 0, 1) f[i][j][k] = inf;
dij();
rep(i, 1, n) rep(j, 1, m) {
int dis = min(f[i][j][0], f[i][j][1]);
if(dis != inf) ans += 1ull * dis * dis;
}
cout << ans << endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 8120kb
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: 1ms
memory: 7820kb
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: 8088kb
input:
5 5 3 1 2 1 1 2 1 ..... .###. .#.#. .###. .....
output:
407
result:
ok single line: '407'
Test #4:
score: 0
Accepted
time: 714ms
memory: 156160kb
input:
3000 2900 1 1882 526 ........................................................................................................#................................................................................................................................................................#................
output:
35141960580077
result:
ok single line: '35141960580077'
Test #5:
score: 0
Accepted
time: 602ms
memory: 152252kb
input:
2900 3000 1 1333 1773 .....#....#......#.#..#...#.....#.#.#.#....#...###.#..#.....##....####..#......#.......######.#........#..#......#...###.#.#..#.....#.#........##..#..#.#..#.###.#.#...#..#.##..#...#....#..#.##..#......#.######............#.#...#......#......#..#.#.#.#...#...#..##........#.###.....
output:
17464052497724
result:
ok single line: '17464052497724'
Test #6:
score: 0
Accepted
time: 16ms
memory: 88336kb
input:
3000 3000 1 2755 225 ##..#.##.....####..#...###.#.##.#.##.#......###.#####..#..####....#.#.####..##..##.#...#...##..#.#.##..#....##.#...#.....##.#...##.##.##..##..#######.####.####......##.##.#....#..#.....#..##.#.#...#.####..##.#..#...###..###.#.#...##.#.....###.####......##...#...#....#.#...#.#.#....
output:
255915
result:
ok single line: '255915'
Test #7:
score: 0
Accepted
time: 24ms
memory: 90124kb
input:
3000 2900 1 878 738 #.##.##..##.#.#.###.#...###.####.#.###.####.##.#.#####.#.####..#.#.###.###..####.####...###..####.########..##..#####.#....#####.#.#########..#.###.##.##.#####.#####.#.##..###..##.#####.#.############..##.###.##.##..########.#.###..###...######.####...#######.###.###..####.######...
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 1366ms
memory: 152444kb
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: 1122ms
memory: 157024kb
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: 0
Accepted
time: 24ms
memory: 89628kb
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:
40571
result:
ok single line: '40571'
Test #11:
score: 0
Accepted
time: 27ms
memory: 86388kb
input:
2900 3000 10 2447 135 2447 136 2447 137 2447 138 2447 139 2447 140 2448 140 2448 139 2449 139 2449 138 .#.##.##..#.###########.#####.###....#####.########..##..#.####.##.##.####.####..#.#####.##.#.#.###.##.#.##.####..##.#.####..###..###...##...##.#####.#####.#...#####.####..##.##.#.#..#..####.##..##...
output:
2705
result:
ok single line: '2705'
Test #12:
score: -100
Wrong Answer
time: 1469ms
memory: 157520kb
input:
3000 3000 100 2573 1917 2572 1917 2572 1916 2573 1916 2574 1916 2574 1915 2573 1915 2572 1915 2571 1915 2571 1914 2570 1914 2570 1915 2569 1915 2569 1916 2568 1916 2568 1917 2569 1917 2570 1917 2570 1916 2571 1916 2571 1917 2571 1918 2570 1918 2569 1918 2569 1919 2570 1919 2571 1919 2571 1920 2572 1...
output:
41693681893201
result:
wrong answer 1st lines differ - expected: '41693682087973', found: '41693681893201'