QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#204502#6739. TeleportkiwiHM#WA 50ms113388kbC++142.0kb2023-10-07 12:21:512023-10-07 12:21:51

Judging History

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

  • [2023-10-07 12:21:51]
  • 评测
  • 测评结果:WA
  • 用时:50ms
  • 内存:113388kb
  • [2023-10-07 12:21:51]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int maxn = 5005;
const int maxv = maxn * maxn;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int n, m, k;
int dis[maxv], fa[maxv];
char s[maxn][maxn];

inline bool valid(int i, int j){ return (i >= 0 && i < n && j >= 0 && j < m && s[i][j] == '.'); }

inline void del(int i, int j){
	if(i + 1 < n && j + 1 < m) fa[i * m + j] = (i + 1) * m + (j + 1);
	else fa[i * m + j] = -1;
}

inline int find(int u){
	if(u == -1 || fa[u] == u) return u;
	return find(fa[u]);
}

queue<int> que;

inline void upd(int si, int sj, int ti, int tj, int w){
	// printf("si = %d sj = %d ti = %d tj = %d\n", si, sj, ti, tj);
	int s = si * m + sj, t = ti * m + tj;
	for(int u = find(si * m + sj), i, j; u != -1 && u <= ti * m + tj; u = find(u)){
		dis[u] = w;
		// printf("upd u = %d\n", u);
		que.push(u);
		i = u / m, j = u % m;
		del(i, j);
		// printf("fa = %d\n", fa[u]);
	}
}

int main(){
	scanf("%d%d", &n, &k);
	m = n;
	for(int i = 0; i < n; ++i){
		scanf("%s", s[i]);
		for(int j = 0; j < m; ++j){
			if(s[i][j] == '.'){
				fa[i * m + j] = i * m + j;
			}
			else{
				if(i + 1 < n && j + 1 < m) fa[i * m + j] = (i + 1) * m + (j + 1);
				else fa[i * m + j] = -1;
			}
		}
	}
	
	memset(dis, 0x3f, sizeof(dis));
	dis[0] = 0;
	del(0, 0);
	for(que.push(0); !que.empty(); que.pop()){
		int u = que.front();
		// printf("u = %d %d\n", u, dis[u]);
		int i = u / m, j = u % m;
		for(int k = 0; k < 4; ++k){
			int ni = i + dx[k], nj = j + dy[k];
			int v = ni * m + nj;
			if(valid(ni, nj) && dis[v] > dis[u] + 1){
				// printf("nei v = %d\n", v);
				dis[v] = dis[u] + 1;
				del(ni, nj);
				que.push(v);
			}
		}
		upd(i + 1, j + 1, i + k / 2, j + k / 2, dis[u] + 1);
		upd(j + 1, i, j + 1 + (k - 1) / 2, i + (k - 1) / 2, dis[u] + 1);
	}
	
	if(dis[(n - 1) * m + (m - 1)] == 0x3f3f3f3f) puts("-1");
	else printf("%d\n", dis[(n - 1) * m + (m - 1)]);
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 103844kb

input:

3 2
.*.
.*.
...

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 3ms
memory: 105712kb

input:

3 3
.*.
.*.
...

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 50ms
memory: 113388kb

input:

961 4
...*.*..*.....*.*..*..*..*.*.*.*.....*.....*....*..*...*....*.........*....*....*...*......*..*..*...*..*...*.....*...*...*.*.*.........**..**.......*.......*...*...*.*.*........*....*..*..*...*.....*.*......**.**..**...*..*.**.....*....*.*.*..*..*..*.*..*.*..*......*..*..*.*......*...*.*...*....

output:

531

result:

wrong answer 1st numbers differ - expected: '540', found: '531'