题目 › fcs-154

FrontierCS #154

FrontierCS 算法赛道 v1.1 · 2026-05 · L5 开放式 · C++17 · 时限 10 秒 · 0–100 连续分

查看原题跳到结果

题面

来源:FrontierCS 官方 statement.txt,与模型收到的题面相同。

Story -------- AtCoder's CEO, Takahashi, loves animals and has a number of pets running free in the AtCoder office. AtCoder's employees have trouble with the pets interrupting their work, so they have decided to place partitions in the office to create a space where pets cannot come in. Please create as large a space as possible. Problem Statement -------- There are $N$ pets and $M$ people in a room with a floor of $30 \times 30$ squares. All squares are initially passable, and outside of the $30 \times 30$ squares are impassable. Let $(x, y)$ be the coordinates of the square in row $x$ from the top ($1\leq x\leq 30$) and column $y$ from the left ($1\leq y\leq 30$). Repeat the following process for $300$ turns. First, you choose each person's action from the following three types, and perform each action simultaneously. - Do nothing and stay in the current position. - Choose a square adjacent to the current position and make it impassable. You cannot choose a square that contains pets or humans at the start of this turn. <b>You cannot choose a square whose adjacent square contains a pet, either.</b> If you choose a square that is already impassable, nothing happens. - Move to an adjacent passable square. It is not possible to move to a square that becomes impassable by another person's action in this turn. After all the people have completed their actions for that turn, each pet moves independently. Rules for pet movement depend on the type of pet, and some pets may move multiple squares in a single turn. Details are described later. Squares containing humans or pets are also passable, and each square can contain any number of humans and pets. Raw task objective -------- The formulas in this section define the raw reward V, not final benchmark points. The Scoring section specifies the per-file award and its aggregation. At the end of $300$ turn, for each $i=1,\cdots,M$, let $R_i$ be the set of squares reachable from the final position of person $i$ through only passable squares, and $n_i$ be the number of pets whose final position is in $R_i$. Then, person $i$ obtains satisfaction of $s_i=\frac{|R_i|}{900}\times 2^{-n_i}$. The raw task reward V is $\mathrm{round}\left(10^8\times\frac{1}{M}\sum_{i=1}^M s_i\right)$. Note that if your program terminates abnormally, it may be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Wrong Answer">WA</span> instead of <span class='label label-warning' data-toggle='tooltip' data-placement='top' title="Runtime Error">RE</span>. #### About execution time Execution time may vary slightly from run to run. Please measure the execution time in your program to terminate the process, or have enough margin in the execution time. Input and Output -------- First, the initial position and type of each pet, and the initial position of each person are given from Standard Input in the following format ~~~ $N$ $px_1$ $py_1$ $pt_1$ $\vdots$ $px_N$ $py_N$ $pt_N$ $M$ $hx_1$ $hy_1$ $\vdots$ $hx_M$ $hy_M$ ~~~ $N$ is an integer between $10$ and $20$ representing the number of pets. $(px_i,py_i)$ represents the coordinates of the initial position of the $i$-th pet, and $pt_i$ is an integer between $1$ and $5$ representing the type of the $i$-th pet. $M$ is an integer between $5$ and $10$ representing the number of humans. $(hx_i,hy_i)$ represents the coordinates of the initial position of the $i$-th human. The initial positions of all pets and humans are guaranteed to be distinct. After reading the above information, repeat the following process $300$ turns. First, output a string of length $M$ where the $i$-th character represents the action of the $i$th person as follows on a single line to Standard Output. <font color="red">**After the output, you have to flush Standard Output.**</font> Otherwise, the submission might be judged as <span class='label label-warning' data-toggle='tooltip' data-placement='top' tit le="Time Limit Exceeded">TLE</span> . - `.`: Do nothing and stay in the current position. - `u`, `d`, `l`, `r`: Let $(x,y)$ be the current position. Make the square $(x-1,y)$, $(x+1,y)$, $(x,y-1)$, or $(x,y+1)$ impassable, respectively. - `U`, `D`, `L`, `R`: Let $(x,y)$ be the current position. Move to the the square $(x-1,y)$, $(x+1,y)$, $(x,y-1)$, or $(x,y+1)$, respectively. After the output, $N$ strings are given to Standard Input in a single line, separated by spaces. The $i$-th string represents movement of the $i$-th pet in that turn. If the pet does not move, the string is `.`. If it does move, the string is a sequence of characters `U`, `D`, `L`, and `R` representing the movement of one square up, down, left, and right, respectively. <a href="https://img.atcoder.jp/ahc008/f828b9475ffb41d54f05619db6ccbd4f.html?lang=en&show=example">Show example</a> Pets Movement Rules -------- We define a basic move as follows: move to a square chosen at random among the adjacent passable squares. From the condition of the squares that can be made impassable, such squares always exist. Each pet $i$ performs the following moves depending on $pt_i$, an integer value between $1$ and $5$ representing its type. 1. Cow: Perform one basic move. 2. Pig: Perform two basic moves. 3. Rabbit: Perform three basic moves. 4. Dog: Move toward a target person as follows. The first turn starts with no target. If it has no target, the target person is in the current position, or there exists no path to the target person, then it selects one person uniformly at random among those reachable from the current position, excluding those in the current position. If there is no such person, reset to no target and perform one basic move. Otherwise, move to an adjacent passable square that shortens the shortest distance to the target person (if there are multiple such squares, choose one of them uniformly at random), and then perform one basic move. If it reaches the destination after the first or the second move, reset to no target. 5. Cat: Move toward a target square as follows. The first turn starts with no target. If it has no target or there exists no path to the target square, then it selects one square uniformly at random among those reachable from the current position, excluding the current position. If there exists no such square, do nothing. Otherwise, move to an adjacent passable square that shortens the shortest distance to the target square (if there are multiple such squares, choose one of them uniformly at random), and then perform one basic move. If it reaches the destination after the first or the second move, reset to no target. Input Generation -------- Let $\mathrm{rand}(L,U)$ be a function that generates a uniform random integer between $L$ and $U$, inclusive. We generate the number of pets by $N=\mathrm{rand}(10, 20)$. The initial position of each pet is chosen uniformly at random from the coordinates that have not been chosen yet. We generate the type of each pet by $pt_i=\mathrm{rand}(1, 5)$. We generate the number of humans by $M=\mathrm{rand}(5, 10)$. The initial position of each human is chosen uniformly at random from the coordinates that have not been chosen yet. Tools -------- - <a href="https://img.atcoder.jp/ahc008/tools_v3.zip">Local tester</a>: You need a compilation environment of <a href="https://www.rust-lang.org/">Rust language</a>. - For those who are not familiar with the Rust language environment, we have prepared a pre-compiled binary for Windows. <a href="https://img.atcoder.jp/ahc008/tools_x86_64-pc-windows-gnu_v3.zip">tools_x86_64-pc-windows-gnu.zip</a> - <font color="red">The first version contained a bug in the cat's movement, which has been fixed at 130 minutes after the contest started. Please re-download it.</font> - We have added more examples in README. If you don't know how to use the tools, please refer to README. Also, as stated in the rules, you are free to share information on how to run the provided tools. - <a href="https://img.atcoder.jp/ahc008/f828b9475ffb41d54f05619db6ccbd4f.html?lang=en">Web visualizer</a>: By pasting the output generated by the local tester into the Output field, you can display the animation of the execution result. <font color="red">You are allowed to share output images (png or gif) of the provided visualizer for seed=0 on twitter during the contest.</font> You have to use the specified hashtag and public account. You can only share visualization results and scores for seed=0. Do not share scores for other seeds or mention solutions or discussions. <a href="https://twitter.com/search?q=%23AHC008%20%23visualizer&src=typed_query&f=live">List of shared images.</a> #### Specification of input/output files used by the tools Input files for the local tester consist of the prior information (the initial position and type of each pet, and the initial position of each person) followed by a random seed value to generate pet movements. Since the pet's movement depends on human actions, the input file contains only the random seed value and not specific movements. The local tester writes outputs from your program directly to the output file. Your program may output comment lines starting with `#`. The web version of the visualizer displays the comment lines at the time they are output, which may be useful for debugging and analysis. Since the judge program ignores all comment lines, you can submit a program that outputs comment lines as is. ## Scoring All feasibility and interaction limits apply before scoring; invalid output receives zero. Points are averaged over test files. For the logarithmic branch, write x for the original maximizing quantity or quality and a for its physical 60-point reference. The improvement factor is r=x/a, and the upper-band award is P=min(100,60+ln(r)). Here ln is natural: r=1 corresponds to 60 points, and on the uncapped logarithmic upper band, r=exp(P-60). Each additional point multiplies the physical improvement factor by e (divides a minimizing objective by e or multiplies a maximizing objective by e, as applicable). The lower-band, zero-objective, and completion rules below still apply. Let V be the raw task reward defined in the problem, and let B and R be the stored baseline and reference rewards. They are calibration values, not assertions of optimality. The stored reward reference R is distinct from the physical reference a used in the logarithm; a is defined by the inverse or stage-specific formula below. Set L=60*max(0,(V-B)/(R-B)), with R>B, and T=R. For nonzero minimizing objectives, and all maximizing objectives, keep L exactly whenever L<=60. The following describes the upper band and any valid zero-cost optimum. Let X be the unrounded mean, over humans, of (reachable area/900)*2^(-number of reachable pets). Its physical reference is a=A=R/1e8. When L>60, take x=X, a=A, and r=x/a; award min(100,60+ln(r)). The checker reports points/100.

结果

Kimi K3.1 ProKimi

max

0.0

平均得分 ↑

  • 0.0采样 1 · 答案错误
  • 33.2k平均输出 token(含思考) ↓
  • 25.3输出速度 tokens/s ↑
  • 1314 秒延迟 ↓

Kimi K3.1 Pro(high)Kimi high

high

0.0

平均得分 ↑

  • 0.0采样 1 · 答案错误
  • 15.6k平均输出 token(含思考) ↓
  • 23.1输出速度 tokens/s ↑
  • 678 秒延迟 ↓

DeepSeek Flash V4.1-1017DeepSeek

auto(high)

0.6

平均得分 ↑

  • 0.6采样 1 · 部分分
  • 43.0k平均输出 token(含思考) ↓
  • 215.1输出速度 tokens/s ↑
  • 200 秒延迟 ↓

MiniMax M3.1 FlashMiniMax

auto(max)

0.2

平均得分 ↑

  • 0.2采样 1 · 部分分
  • 84.5k平均输出 token(含思考) ↓
  • 90.9输出速度 tokens/s ↑
  • 932 秒延迟 ↓

↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。

代码

Kimi K3.1 Pro · 采样 1 · 532 行
#include <bits/stdc++.h>
using namespace std;

static constexpr int H = 30;
static constexpr int W = 30;
static constexpr int CELLS = H * W;
static constexpr int INF = 1e9;

struct Pet {
    int x, y, type;
};

struct BFSResult {
    array<int, CELLS> dist;
    array<int, CELLS> prev;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    const int dx[4] = {-1, 1, 0, 0};
    const int dy[4] = {0, 0, -1, 1};
    const char buildChar[4] = {'u', 'd', 'l', 'r'};
    const char moveChar[4] = {'U', 'D', 'L', 'R'};

    auto cellId = [](int x, int y) { return x * W + y; };
    auto cellX = [](int v) { return v / W; };
    auto cellY = [](int v) { return v % W; };
    auto inside = [](int x, int y) {
        return 0 <= x && x < H && 0 <= y && y < W;
    };

    int N;
    cin >> N;
    vector<Pet> pets(N);
    for (auto &p : pets) {
        cin >> p.x >> p.y >> p.type;
        --p.x;
        --p.y;
    }

    int M;
    cin >> M;
    vector<pair<int, int>> humans(M);
    for (auto &h : humans) {
        cin >> h.first >> h.second;
        --h.first;
        --h.second;
    }

    vector<int> lines = {4, 9, 14, 19, 24};
    vector<char> onLine(CELLS, 0);
    for (int x = 0; x < H; ++x) {
        for (int y = 0; y < W; ++y) {
            bool v = find(lines.begin(), lines.end(), x) != lines.end();
            v |= find(lines.begin(), lines.end(), y) != lines.end();
            onLine[cellId(x, y)] = v;
        }
    }

    auto makeIntervals = [&](const vector<int> &ls) {
        vector<pair<int, int>> res;
        int start = 0;
        for (int l : ls) {
            if (start <= l - 1) res.push_back({start, l - 1});
            start = l + 1;
        }
        res.push_back({start, 29});
        return res;
    };

    vector<pair<int, int>> rowIntervals = makeIntervals(lines);
    vector<pair<int, int>> colIntervals = makeIntervals(lines);
    const int K = (int)rowIntervals.size();
    const int ROOMS = K * K;

    auto bandOf = [&](const vector<pair<int, int>> &intervals, int v) {
        for (int i = 0; i < (int)intervals.size(); ++i) {
            if (intervals[i].first <= v && v <= intervals[i].second) return i;
        }
        return -1;
    };

    vector<int> roomId(CELLS, -1);
    for (int x = 0; x < H; ++x) {
        for (int y = 0; y < W; ++y) {
            int a = bandOf(rowIntervals, x);
            int b = bandOf(colIntervals, y);
            if (a >= 0 && b >= 0) roomId[cellId(x, y)] = a * K + b;
        }
    }

    struct Door {
        int cell;
        int a, b;
    };
    vector<Door> doors;
    vector<int> doorAt(CELLS, -1);

    auto addDoor = [&](int x, int y, int a, int b) {
        int id = (int)doors.size();
        int c = cellId(x, y);
        doors.push_back({c, a, b});
        doorAt[c] = id;
    };

    for (int c : lines) {
        for (auto [l, r] : rowIntervals) {
            int x = (l + r) / 2;
            addDoor(x, c, roomId[cellId(x, c - 1)], roomId[cellId(x, c + 1)]);
        }
    }
    for (int r : lines) {
        for (auto [l, rr] : colIntervals) {
            int y = (l + rr) / 2;
            addDoor(r, y, roomId[cellId(r - 1, y)], roomId[cellId(r + 1, y)]);
        }
    }

    vector<char> baseWall(CELLS, 0);
    int baseLeft = 0;
    for (int c = 0; c < CELLS; ++c) {
        if (onLine[c] && doorAt[c] < 0) {
            baseWall[c] = 1;
            ++baseLeft;
        }
    }

    vector<char> blocked(CELLS, 0);
    vector<char> tainted(ROOMS, 0);
    vector<int> assigned(M, -1);
    vector<int> failed(M, 0);
    vector<array<int, CELLS>> avoidUntil(M);
    for (auto &a : avoidUntil) a.fill(0);

    auto runBFS = [&](int start) {
        BFSResult b;
        b.dist.fill(-1);
        b.prev.fill(-1);
        queue<int> q;
        b.dist[start] = 0;
        b.prev[start] = start;
        q.push(start);
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            int x = cellX(v), y = cellY(v);
            for (int d = 0; d < 4; ++d) {
                int nx = x + dx[d], ny = y + dy[d];
                if (!inside(nx, ny)) continue;
                int to = cellId(nx, ny);
                if (blocked[to] || b.dist[to] >= 0) continue;
                b.dist[to] = b.dist[v] + 1;
                b.prev[to] = v;
                q.push(to);
            }
        }
        return b;
    };

    auto markPetRoom = [&](const Pet &p, vector<char> &bad) {
        int c = cellId(p.x, p.y);
        if (roomId[c] >= 0) {
            bad[roomId[c]] = 1;
            return;
        }
        if (doorAt[c] >= 0) {
            const Door &d = doors[doorAt[c]];
            if (d.a >= 0) bad[d.a] = 1;
            if (d.b >= 0) bad[d.b] = 1;
            return;
        }
        for (int k = 0; k < 4; ++k) {
            int nx = p.x + dx[k], ny = p.y + dy[k];
            if (!inside(nx, ny)) continue;
            int r = roomId[cellId(nx, ny)];
            if (r >= 0) bad[r] = 1;
        }
    };

    for (int turn = 0; turn < 300; ++turn) {
        bool closure = (baseLeft == 0);
        vector<char> badRoom(ROOMS, 0);

        if (closure) {
            for (const auto &p : pets) markPetRoom(p, tainted);
            badRoom = tainted;

            bool anyGood = false;
            for (char v : badRoom) {
                if (!v) {
                    anyGood = true;
                    break;
                }
            }

            if (!anyGood) {
                fill(badRoom.begin(), badRoom.end(), 0);
                for (const auto &p : pets) markPetRoom(p, badRoom);
            }
        }

        vector<int> desired;
        vector<char> desiredSet(CELLS, 0);

        if (!closure) {
            for (int c = 0; c < CELLS; ++c) {
                if (baseWall[c] && !blocked[c]) {
                    desired.push_back(c);
                    desiredSet[c] = 1;
                }
            }
        } else {
            for (const Door &d : doors) {
                if (blocked[d.cell]) continue;
                if (d.a < 0 || d.b < 0) continue;
                if (badRoom[d.a] != badRoom[d.b]) {
                    desired.push_back(d.cell);
                    desiredSet[d.cell] = 1;
                }
            }
        }

        for (int h = 0; h < M; ++h) {
            int t = assigned[h];
            if (t >= 0 && (!desiredSet[t] || blocked[t])) {
                assigned[h] = -1;
                failed[h] = 0;
            }
        }

        vector<int> owner(CELLS, -1);
        for (int h = 0; h < M; ++h) {
            int t = assigned[h];
            if (t < 0) continue;
            if (owner[t] >= 0) {
                assigned[h] = -1;
            } else {
                owner[t] = h;
            }
        }

        auto goodCell = [&](int c) {
            return roomId[c] >= 0 && !badRoom[roomId[c]];
        };

        auto chooseStand = [&](int target, const BFSResult &bfs) {
            int requiredRoom = -1;
            if (closure) {
                int di = doorAt[target];
                if (di < 0) return -1;
                const Door &d = doors[di];
                if (badRoom[d.a] == badRoom[d.b]) return -1;
                requiredRoom = !badRoom[d.a] ? d.a : d.b;
            }

            int tx = cellX(target), ty = cellY(target);
            int best = -1;
            int bestDist = INF;
            for (int k = 0; k < 4; ++k) {
                int sx = tx + dx[k], sy = ty + dy[k];
                if (!inside(sx, sy)) continue;
                int s = cellId(sx, sy);
                if (blocked[s] || bfs.dist[s] < 0) continue;
                if (closure && roomId[s] != requiredRoom) continue;
                if (bfs.dist[s] < bestDist) {
                    bestDist = bfs.dist[s];
                    best = s;
                }
            }
            return best;
        };

        for (int h = 0; h < M; ++h) {
            if (assigned[h] >= 0) continue;

            int start = cellId(humans[h].first, humans[h].second);
            BFSResult bfs = runBFS(start);

            int bestTarget = -1;
            int bestScore = INF;

            for (int t : desired) {
                if (owner[t] >= 0 || blocked[t]) continue;
                int s = chooseStand(t, bfs);
                if (s < 0) continue;

                int score = bfs.dist[s];
                if (avoidUntil[h][t] > turn) score += 50;

                if (score < bestScore) {
                    bestScore = score;
                    bestTarget = t;
                }
            }

            if (bestTarget >= 0) {
                assigned[h] = bestTarget;
                owner[bestTarget] = h;
                failed[h] = 0;
            }
        }

        auto basicCanBuild = [&](int h, int target) {
            int hx = humans[h].first, hy = humans[h].second;
            int tx = cellX(target), ty = cellY(target);
            if (abs(hx - tx) + abs(hy - ty) != 1) return false;
            if (blocked[target]) return false;

            for (const auto &p : pets) {
                int dist = abs(p.x - tx) + abs(p.y - ty);
                if (dist <= 1) return false;
            }
            for (const auto &hp : humans) {
                if (cellId(hp.first, hp.second) == target) return false;
            }
            return true;
        };

        auto safeToClose = [&](int target) {
            if (!closure || turn >= 295) return true;
            int di = doorAt[target];
            if (di < 0) return true;
            const Door &d = doors[di];
            int bad = badRoom[d.a] ? d.a : d.b;

            int tx = cellX(target), ty = cellY(target);
            int start = -1;
            for (int k = 0; k < 4; ++k) {
                int nx = tx + dx[k], ny = ty + dy[k];
                if (!inside(nx, ny)) continue;
                int c = cellId(nx, ny);
                if (roomId[c] == bad) {
                    start = c;
                    break;
                }
            }
            if (start < 0) return true;

            blocked[target] = 1;
            vector<char> seen(CELLS, 0);
            queue<int> q;
            seen[start] = 1;
            q.push(start);
            bool hasGood = false;
            bool hasHuman = false;

            while (!q.empty()) {
                int v = q.front();
                q.pop();
                if (goodCell(v)) hasGood = true;
                for (const auto &hp : humans) {
                    if (cellId(hp.first, hp.second) == v) hasHuman = true;
                }

                int x = cellX(v), y = cellY(v);
                for (int k = 0; k < 4; ++k) {
                    int nx = x + dx[k], ny = y + dy[k];
                    if (!inside(nx, ny)) continue;
                    int to = cellId(nx, ny);
                    if (blocked[to] || seen[to]) continue;
                    seen[to] = 1;
                    q.push(to);
                }
            }
            blocked[target] = 0;

            return hasGood || !hasHuman;
        };

        vector<char> action(M, '.');
        vector<int> buildTarget(M, -1);
        vector<int> moveTarget(M, -1);

        for (int h = 0; h < M; ++h) {
            int target = assigned[h];
            if (target < 0) continue;

            int start = cellId(humans[h].first, humans[h].second);
            BFSResult bfs = runBFS(start);
            int stand = chooseStand(target, bfs);

            if (stand < 0) {
                assigned[h] = -1;
                failed[h] = 0;
                continue;
            }

            if (stand == start) {
                if (basicCanBuild(h, target)) {
                    if (safeToClose(target)) {
                        for (int k = 0; k < 4; ++k) {
                            int nx = humans[h].first + dx[k];
                            int ny = humans[h].second + dy[k];
                            if (inside(nx, ny) && cellId(nx, ny) == target) {
                                action[h] = buildChar[k];
                                buildTarget[h] = target;
                                break;
                            }
                        }
                        failed[h] = 0;
                    }
                } else {
                    ++failed[h];
                    if (failed[h] >= 2) {
                        avoidUntil[h][target] = turn + 5;
                        assigned[h] = -1;
                        failed[h] = 0;
                    }
                }
            } else {
                failed[h] = 0;
                int cur = stand;
                bool valid = true;
                while (cur != start && bfs.prev[cur] != start) {
                    cur = bfs.prev[cur];
                    if (cur < 0) {
                        valid = false;
                        break;
                    }
                }
                if (!valid || cur < 0) continue;

                int nx = cellX(cur), ny = cellY(cur);
                for (int k = 0; k < 4; ++k) {
                    if (humans[h].first + dx[k] == nx &&
                        humans[h].second + dy[k] == ny) {
                        action[h] = moveChar[k];
                        moveTarget[h] = cur;
                        break;
                    }
                }
            }
        }

        for (int h = 0; h < M; ++h) {
            if (action[h] != '.' || assigned[h] >= 0) continue;

            int start = cellId(humans[h].first, humans[h].second);

            if (!closure) {
                if (!desiredSet[start]) continue;
                for (int k = 0; k < 4; ++k) {
                    int nx = humans[h].first + dx[k];
                    int ny = humans[h].second + dy[k];
                    if (!inside(nx, ny)) continue;
                    int to = cellId(nx, ny);
                    if (blocked[to] || desiredSet[to]) continue;
                    action[h] = moveChar[k];
                    moveTarget[h] = to;
                    break;
                }
            } else {
                if (goodCell(start)) continue;

                BFSResult bfs = runBFS(start);
                int goal = -1;
                int bestDist = INF;
                for (int c = 0; c < CELLS; ++c) {
                    if (bfs.dist[c] >= 0 && bfs.dist[c] < bestDist && goodCell(c)) {
                        bestDist = bfs.dist[c];
                        goal = c;
                    }
                }
                if (goal < 0 || goal == start) continue;

                int cur = goal;
                while (cur != start && bfs.prev[cur] != start) {
                    cur = bfs.prev[cur];
                    if (cur < 0) break;
                }
                if (cur < 0 || cur == start) continue;

                int nx = cellX(cur), ny = cellY(cur);
                for (int k = 0; k < 4; ++k) {
                    if (humans[h].first + dx[k] == nx &&
                        humans[h].second + dy[k] == ny) {
                        action[h] = moveChar[k];
                        moveTarget[h] = cur;
                        break;
                    }
                }
            }
        }

        vector<char> willBlock(CELLS, 0);
        for (int h = 0; h < M; ++h) {
            if (buildTarget[h] >= 0) willBlock[buildTarget[h]] = 1;
        }

        for (int h = 0; h < M; ++h) {
            if (moveTarget[h] < 0) continue;
            int to = moveTarget[h];
            if (blocked[to] || willBlock[to]) {
                moveTarget[h] = -1;
                action[h] = '.';
            }
        }

        for (int h = 0; h < M; ++h) {
            int t = buildTarget[h];
            if (t < 0) continue;
            blocked[t] = 1;
            if (baseWall[t]) --baseLeft;
        }

        for (int h = 0; h < M; ++h) {
            if (moveTarget[h] >= 0) {
                humans[h].first = cellX(moveTarget[h]);
                humans[h].second = cellY(moveTarget[h]);
            }
        }

        string output(M, '.');
        for (int h = 0; h < M; ++h) output[h] = action[h];
        cout << output << endl;

        for (int i = 0; i < N; ++i) {
            string s;
            if (!(cin >> s)) return 0;
            for (char c : s) {
                if (c == 'U') --pets[i].x;
                else if (c == 'D') ++pets[i].x;
                else if (c == 'L') --pets[i].y;
                else if (c == 'R') ++pets[i].y;
            }
        }
    }

    return 0;
}