QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#345161#8236. Snake MoveoscaryangzjWA 1836ms296672kbC++202.1kb2024-03-06 11:47:352024-03-06 11:47:37

Judging History

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

  • [2024-03-06 11:47:37]
  • 评测
  • 测评结果:WA
  • 用时:1836ms
  • 内存:296672kb
  • [2024-03-06 11:47:35]
  • 提交

answer

#include<bits/stdc++.h>

#define int long long
#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 = 1e18;
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) && d + 1 < f[nx][ny][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: 0ms
memory: 7856kb

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

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

input:

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

output:

407

result:

ok single line: '407'

Test #4:

score: 0
Accepted
time: 974ms
memory: 296656kb

input:

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

output:

35141960580077

result:

ok single line: '35141960580077'

Test #5:

score: 0
Accepted
time: 750ms
memory: 289100kb

input:

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

output:

17464052497724

result:

ok single line: '17464052497724'

Test #6:

score: 0
Accepted
time: 36ms
memory: 159424kb

input:

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

output:

255915

result:

ok single line: '255915'

Test #7:

score: 0
Accepted
time: 35ms
memory: 157328kb

input:

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

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 1699ms
memory: 288800kb

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: 1389ms
memory: 296588kb

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: 34ms
memory: 157412kb

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: 33ms
memory: 152508kb

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: 1836ms
memory: 296672kb

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'