QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#717175#8981. Kangaroo PuzzleKobicGendWA 1ms3652kbC++231.5kb2024-11-06 17:07:502024-11-06 17:07:50

Judging History

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

  • [2024-11-06 17:07:50]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3652kb
  • [2024-11-06 17:07:50]
  • 提交

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;
}

详细

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