QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#726422 | #8981. Kangaroo Puzzle | yell | TL | 1ms | 3648kb | C++20 | 1.5kb | 2024-11-09 00:15:23 | 2024-11-09 00:15:24 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
void solve() {
int n, m;
cin >> n >> m;
vector<string> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
queue<pair<set<pair<int, int>>, string>> q;
set<pair<int, int>> init;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] == '1') {
init.emplace(i, j);
}
}
}
q.emplace(init, "");
string d = "UDLR";
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int mn = 1e9;
while (!q.empty()) {
auto [v, s] = q.front();
q.pop();
if (v.size() > mn) {
continue;
}
mn = min(mn, (int)v.size());
if (v.size() <= 1) {
cout << s << "\n";
return;
}
for (int i = 0; i < 4; i++) {
set<pair<int, int>> st;
for (auto [x, y] : v) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || nx >= n || ny < 0 || ny >= m || a[nx][ny] == '0') {
nx = x;
ny = y;
}
st.emplace(nx, ny);
}
q.emplace(st, s + d[i]);
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3588kb
input:
4 4 1111 1001 1001 1110
output:
UULLULUU
result:
ok AC
Test #2:
score: 0
Accepted
time: 1ms
memory: 3648kb
input:
2 15 111111111111111 101010101010101
output:
ULLLLLLLLLLLLLL
result:
ok AC
Test #3:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
1 2 11
output:
L
result:
ok AC
Test #4:
score: -100
Time Limit Exceeded
input:
20 20 00000000000000000000 00000000000000000000 00000000000000000000 00000000000000010000 00000000000000010100 00000000000000111110 11001100000001101001 01110100111001000111 10011111101111001101 11110100110101001001 01000000001101011101 00000000000011010000 01000000000110010000 11100000001010110000 ...