QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#17977#2213. Knightlaihaochen#RE 40ms12468kbC++171.7kb2022-01-15 15:51:092022-05-04 16:34:10

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-04 16:34:10]
  • 评测
  • 测评结果:RE
  • 用时:40ms
  • 内存:12468kb
  • [2022-01-15 15:51:09]
  • 提交

answer

#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 1005;
int n, m, r, c, sx, sy, ex, ey;
char s[N][N];
int col[N][N];
int dx[] = {1, 1, -1, -1};
int dy[] = {1, -1, 1, -1};
void dfs1 (int x, int y, int ch) {
	col[x][y] = ch;
	for (int i = 0; i < 4; i++) {
		int nx = x + dx[i] * r, ny = y + dy[i] * c;
		if (1 <= nx && nx <= n && 1 <= ny && ny <= m && s[nx][ny] != '@' && !col[nx][ny]) {
			dfs1 (nx, ny, 3 - ch);
		} 
	}
	for (int i = 0; i < 4; i++) {
		int nx = x + dx[i] * c, ny = y + dy[i] * r;
		if (1 <= nx && nx <= n && 1 <= ny && ny <= m && s[nx][ny] != '@' && !col[nx][ny]) {
			dfs1 (nx, ny, 3 - ch);
		} 
	}
}
int sz;
bool flag, vis[N][N];
void dfs2 (int x, int y) {
	vis[x][y] = 1, sz++;
	if (x == ex && ey == y) flag = 1;
	for (int i = 0; i < 4; i++) {
		int nx = x + dx[i] * r, ny = y + dy[i] * c;
		if (1 <= nx && nx <= n && 1 <= ny && ny <= m && s[nx][ny] != '@' && !vis[nx][ny]) {
			dfs2 (nx, ny);
		} 
	}
	for (int i = 0; i < 4; i++) {
		int nx = x + dx[i] * c, ny = y + dy[i] * r;
		if (1 <= nx && nx <= n && 1 <= ny && ny <= m && s[nx][ny] != '@' && !vis[nx][ny]) {
			dfs2 (nx, ny);
		} 
	}
} 
int main() {
	scanf ("%d%d%d%d", &n, &m, &r, &c);
	for (int i = 1; i <= n; i++) {
		scanf ("%s", s[i] + 1);
		for (int j = 1; j <= m; j++) {
			if (s[i][j] == 'A') sx = i, sy = j;
			if (s[i][j] == 'B') ex = i, ey = j;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (!col[i][j] && s[i][j] != '@') dfs1 (i, j, 1);		
		}
	}
	dfs2 (sx, sy);
	if (sz == 1) {
		printf ("Bob\n");
	} else if (!flag) {
		printf ("Alice\n");
	} else {
		printf (col[sz][sy] == col[ex][ey] ? "Alice\n" : "Bob\n");
	}
	return 0;
} 

詳細信息

Test #1:

score: 100
Accepted
time: 6ms
memory: 6556kb

Test #2:

score: 0
Accepted
time: 0ms
memory: 3928kb

Test #3:

score: 0
Accepted
time: 40ms
memory: 12468kb

Test #4:

score: -100
Runtime Error