QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#717150#8981. Kangaroo PuzzleKobicGendWA 0ms3592kbC++231.5kb2024-11-06 17:03:342024-11-06 17:03:34

Judging History

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

  • [2024-11-06 17:03:34]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3592kb
  • [2024-11-06 17:03:34]
  • 提交

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);
            }
        };
        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: 3592kb

input:

4 4
1111
1001
1001
1110

output:

LLUUURRRDD

result:

ok AC

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3580kb

input:

2 15
111111111111111
101010101010101

output:

ULLDLLDLLDLLDLLDLLDLLD

result:

wrong answer WA