QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#717175 | #8981. Kangaroo Puzzle | KobicGend | WA | 1ms | 3652kb | C++23 | 1.5kb | 2024-11-06 17:07:50 | 2024-11-06 17:07:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int dx[] = { 1, 0, -1, 0 };
const int dy[] = { 0, 1, 0, -1 };
const string dir = "DRUL";
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int n, m;
cin >> n >> m;
vector<string> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
vector<vector<int>> E(n * m);
auto change = [&](int x, int y) {
return x * m + y;
};
auto get = [&](int p) {
return pair(p / m, p % m);
};
int sx = -1, sy = -1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (s[i][j] == '1') {
sx = i, sy = j;
}
}
}
vector vis(n, vector<int>(m));
string path;
if (sx != -1) {
auto dfs = [&](auto&& self, int x, int y) -> void {
//cerr << "dfs " << x << " " << y << endl;
for (int i = 0; i < 4; i++) {
auto [nx, ny] = pair(x + dx[i], y + dy[i]);
if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
if (s[nx][ny] == '0') continue;
if (vis[nx][ny]) continue;
vis[nx][ny] = 1;
path += dir[i];
self(self, nx, ny);
path += dir[(i + 2) % 4];
}
};
vis[sx][sy] = 1;
dfs(dfs, sx, sy);
}
cout << path << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3652kb
input:
4 4 1111 1001 1001 1110
output:
LLUUURRRDDUULLLDDDRR
result:
ok AC
Test #2:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
2 15 111111111111111 101010101010101
output:
ULLDULLDULLDULLDULLDULLDULLDURRRRRRRRRRRRRRD
result:
ok AC
Test #3:
score: 0
Accepted
time: 1ms
memory: 3652kb
input:
1 2 11
output:
LR
result:
ok AC
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3640kb
input:
20 20 00000000000000000000 00000000000000000000 00000000000000000000 00000000000000010000 00000000000000010100 00000000000000111110 11001100000001101001 01110100111001000111 10011111101111001101 11110100110101001001 01000000001101011101 00000000000011010000 01000000000110010000 11100000001010110000 ...
output:
LLUUURURRDRRURRRDRRLLULLUUUUURRLUURURRDDDUUUUDLLDLDDLDDDLRDDLDLLUURLUUURUUUUURURRDURRLUDLLUUDDLDLDDLLDDLRUULULLDDRLULLLDUUULRDDLLDLLDULUDRRRUULLULRDRRDRRRRRURRDRRRDDDLDLRDDDLLUUDLRDDLLUDLRRDDDLLLUUDLLULULULUURLUDLRDDLDDDRDURLLUUURRDRDRDRRDRRRRR
result:
wrong answer WA