QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#394519 | #7751. Palindrome Path | luanmenglei | WA | 0ms | 3584kb | C++17 | 3.0kb | 2024-04-20 15:36:48 | 2024-04-20 15:36:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
namespace SOL {
using i64 = long long;
void debug(const char *msg, ...) {
#ifdef CLESIP
va_list arg;
static char pbString[512];
va_start(arg,msg);
vsprintf(pbString,msg,arg);
cerr << "[DEBUG] " << pbString << "\n";
va_end(arg);
#endif
}
template<typename T, typename L>
bool chkmax(T &x, L y) { if (x < y) return x = y, true; return false; }
template<typename T, typename L>
bool chkmin(T &x, L y) { if (y < x) return x = y, true; return false; }
const int N = 35;
const int dx[] = { 1, -1, 0, 0 };
const int dy[] = { 0, 0, 1, -1 };
const int neg[] = { 1, 0, 3, 2 };
const char wrd[] = { 'U', 'D', 'R', 'L' };
int n, m;
char pic[N][N];
array<int, 2> st, ed;
bool tvis[N][N], vis[N][N][N][N];
array<int, 5> lst[N][N][N][N];
vector<int> travel;
queue<array<int, 4>> q;
void dfs(int x, int y) {
// debug("dfs (%d, %d)", x, y);
tvis[x][y] = true;
for (int i = 0; i < 4; i ++) {
int xx = x + dx[i], yy = y + dy[i];
// debug("try (%d, %d)", xx, yy);
if (xx >= 1 && yy >= 1 && xx <= n && yy <= m && !tvis[xx][yy] && pic[xx][yy] == '1') {
travel.push_back(i);
dfs(xx, yy);
travel.push_back(neg[i]);
}
}
}
array<int, 2> walk(int x, int y, int op) {
int xx = x + dx[op], yy = y + dy[op];
if (pic[xx][yy] == '0' || xx < 1 || yy < 1 || xx > n || yy > m)
return { x, y };
return { xx, yy };
}
void bfs() {
lst[st[0]][st[1]][ed[0]][ed[1]][0] = -1;
vis[st[0]][st[1]][ed[0]][ed[1]] = true;
q.push({ st[0], st[1], ed[0], ed[1] });
while (!q.empty()) {
auto [x, y, u, v] = q.front(); q.pop();
if (x == u && y == v) {
vector<int> ans;
while (lst[x][y][u][v][0] != -1) {
auto [op, xx, yy, uu, vv] = lst[x][y][u][v];
ans.push_back(op);
x = xx, y = yy, u = uu, v = vv;
}
for (int i = 0; i < int(travel.size()); i ++)
cout << wrd[travel[i]];
cerr << "\n";
for (int i = int(ans.size()) - 1; i >= 0; i --)
cout << wrd[ans[i]];
cerr << "\n";
for (int i = 0; i < int(ans.size()); i ++)
cout << wrd[ans[i]];
cerr << "\n";
for (int i = int(travel.size()) - 1; i >= 0; i --)
cout << wrd[travel[i]];
return;
}
for (int i = 0; i < 4; i ++) {
auto [xx, yy] = walk(x, y, i);
auto [uu, vv] = walk(u, v, i);
if (vis[xx][yy][uu][vv])
continue;
vis[xx][yy][uu][vv] = true;
lst[xx][yy][uu][vv] = { i, x, y, u, v };
q.push({ xx, yy, uu, vv });
}
}
assert(false);
}
void solve() {
cin >> n >> m;
for (int i = 1; i <= n; i ++)
cin >> (pic[i] + 1);
cin >> st[0] >> st[1] >> ed[0] >> ed[1];
dfs(ed[0], ed[1]);
for (int i = 1; i <= n; i ++)
for (int j = 1; j <= m; j ++)
if (!tvis[i][j] && pic[i][j] == '1')
return cout << "-1\n", void();
for (int i = 0; i < (int) travel.size(); i ++)
st = walk(st[0], st[1], travel[i]);
bfs();
}
}
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
SOL::solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3584kb
input:
2 2 11 11 1 1 2 2
output:
DLUDRUURDULD
result:
wrong answer End Point Is (2,1), Not (er = 2, ec = 2)