QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#479070#7751. Palindrome Pathucup-team052#WA 2ms12204kbC++142.3kb2024-07-15 14:38:312024-07-15 14:38:32

Judging History

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

  • [2024-07-15 14:38:32]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:12204kb
  • [2024-07-15 14:38:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const char dc[4] = {'R', 'L', 'D', 'U'};

const int N = 905;

char c[35][35];
queue < pair <int, int> > q;
int frx[N][N], fry[N][N], fr[N][N], vis[N][N];
int n, m, sx, sy, tx, ty;

inline int s(int x, int y) { return (x - 1) * m + y; }

int seq[N * N], len;
void solve(int x, int y) {
	if (!frx[x][y]) return;
	solve(frx[x][y], fry[x][y]);
	seq[++len] = fr[x][y];
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%s", c[i] + 1);
	scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
	q.push(make_pair(s(sx, sy), s(tx, ty))); vis[s(sx, sy)][s(tx, ty)] = 1;
	while (!q.empty()) {
		pair <int, int> t = q.front(); q.pop();
		int ux1 = (t.first - 1) / m + 1, uy1 = (t.first - 1) % m + 1;
		int ux2 = (t.second - 1) / m + 1, uy2 = (t.second - 1) % m + 1;
		for (int d = 0; d < 4; d++) {
			for (int i = 0; i <= 1; i++) {
				int x1, y1, x2, y2;
				x1 = ux1 + dx[d]; y1 = uy1 + dy[d];
				if (x1 < 1 || x1 > n || y1 < 1 || y1 > m || c[x1][y1] == '0') x1 = ux1, y1 = uy1;
				if (i) {
					x2 = ux2 + dx[d ^ 1], y2 = uy2 + dy[d ^ 1];
					if (x2 < 1 || x2 > n || y2 < 1 || y2 > m || c[x2][y2] == '0') continue;
				} else {
					x2 = ux2 + dx[d], y2 = uy2 + dy[d];
					if (x2 >= 1 && x2 <= n && y2 >= 1 && y2 <= m && c[x2][y2] == '1') continue;
					x2 = ux2; y2 = uy2;
				}
				int t1 = s(x1, y1), t2 = s(x2, y2);
				if (vis[t1][t2]) continue;
				vis[t1][t2] = 1; frx[t1][t2] = t.first; fry[t1][t2] = t.second; fr[t1][t2] = d; q.push(make_pair(t1, t2));
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			int t = s(i, j);
			if (vis[t][t]) {
				solve(t, t);
				for (int k = 1; k <= len; k++) printf("%c", dc[seq[k]]);
				for (int k = len; k >= 1; k--) printf("%c", dc[seq[k]]);
				return 0;
			}
			for (int d = 0; d < 4; d++) {
				int x = i + dx[d], y = j + dy[d];
				if (x >= 1 && x <= n && y >= 1 && y <= m && c[x][y] == '1' && vis[t][s(x, y)]) {
					solve(t, s(x, y));
					for (int k = 1; k <= len; k++) printf("%c", dc[seq[k]]);
					printf("%c", dc[d]);
					for (int k = len; k >= 1; k--) printf("%c", dc[seq[k]]);
					return 0;
				}
			}
		}
	}
	printf("-1\n");
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 11860kb

input:

2 2
11
11
1 1 2 2

output:

RLDUUDLR

result:

ok Valid Solution (Length = 8).

Test #2:

score: 0
Accepted
time: 1ms
memory: 5760kb

input:

2 2
10
01
1 1 2 2

output:

-1

result:

ok No Solution.

Test #3:

score: 0
Accepted
time: 1ms
memory: 5948kb

input:

1 1
1
1 1 1 1

output:


result:

ok Valid Solution (Length = 0).

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 12204kb

input:

5 4
1111
1111
1111
1111
1111
4 2 4 2

output:

RRRLLLLDUUUUDLLLLRRR

result:

wrong answer End Point Is (2,4), Not (er = 4, ec = 2)