QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#508386#7965. 机器人vorDealRE 0ms0kbC++203.7kb2024-08-07 14:28:242024-08-07 14:28:25

Judging History

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

  • [2024-08-07 14:28:25]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-08-07 14:28:24]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int n, m, k, cnt;
struct command
{
    string type;
    int h, x, y, z;
    string con;
    int sub;
} cmd[500005];

struct robot
{
    int hd[2], act[25];
} rbt[505];

int read();
int mirror(int ord);
void activate(int id);
void run(int id, int ord, bool f);

int main()
{
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> rbt[i].hd[0] >> rbt[i].hd[1];
        for (int j = 1; j <= m; j++)
            rbt[i].act[j] = read();
    }
    for (int i = 0; k; i++)
        activate(i % n);
    return 0;
}

int read()
{
    int id = cnt++;
    cin >> cmd[id].type;
    if (cmd[id].type == "MOVE")
        cin >> cmd[id].h >> cmd[id].z;
    else if (cmd[id].type == "SWAP")
        cin >> cmd[id].h >> cmd[id].x >> cmd[id].y;
    else if (cmd[id].type == "MIRROR")
        cin >> cmd[id].h >> cmd[id].x;
    else if (cmd[id].type == "REPLACE")
        cin >> cmd[id].h >> cmd[id].x, cmd[id].sub = read();
    else if (cmd[id].type == "ACTIVATE")
        cin >> cmd[id].h;
    else if (cmd[id].type == "TRIGGER")
        cin >> cmd[id].con, cmd[id].con.pop_back(), cmd[id].sub = read();
    return id;
}

int mirror(int ord)
{
    if (cmd[ord].type == "SLACKOFF")
        return ord;
    if (cmd[ord].type == "TRIGGER")
    {
        cmd[cnt] = cmd[ord];
        cmd[cnt + 1] = cmd[cmd[ord].sub];
        cmd[cnt].sub = cnt + 1;
        cmd[cnt + 1].h = (cmd[cnt + 1].h == 0 ? 1 : 0);
        cnt += 2;
        return cnt - 2;
    }
    cmd[cnt] = cmd[ord];
    cmd[cnt].h = (cmd[cnt].h == 0 ? 1 : 0);
    return cnt++;
}

void activate(int id)
{
    for (int i = 1; i <= m; i++)
        if (cmd[rbt[id].act[i]].type != "TRIGGER")
            run(id, rbt[id].act[i], false);
    return;
}

void run(int id, int ord, bool f)
{
    if (k <= 0)
        exit(0);
    if (cmd[ord].type == "SLACKOFF")
    {
        printf("Robot %d slacks off.\n", id);
        k--;
    }
    else if (cmd[ord].type == "MOVE")
    {
        rbt[id].hd[cmd[ord].h] += cmd[ord].z;
        rbt[id].hd[cmd[ord].h] %= n;
        printf("Robot %d moves its %s hand towards Robot %d.\n", id,
               (cmd[ord].h == 0 ? "left" : "right"), rbt[id].hd[cmd[ord].h]);
        k--;
    }
    else if (cmd[ord].type == "SWAP")
    {
        swap(rbt[id].act[cmd[ord].y], rbt[rbt[id].hd[cmd[ord].h]].act[cmd[ord].x]);
        printf("Robot %d swaps a line of command with Robot %d.\n", id, rbt[id].hd[cmd[ord].h]);
        k--;
    }
    else if (cmd[ord].type == "MIRROR")
    {
        rbt[rbt[id].hd[cmd[ord].h]].act[cmd[ord].x] = mirror(rbt[rbt[id].hd[cmd[ord].h]].act[cmd[ord].x]);
        printf("Robot %d modifies a line of command of Robot %d.\n", id, rbt[id].hd[cmd[ord].h]);
        k--;
    }
    else if (cmd[ord].type == "REPLACE")
    {
        cmd[cnt] = cmd[cmd[ord].sub];
        rbt[rbt[id].hd[cmd[ord].h]].act[cmd[ord].x] = cnt++;
        printf("Robot %d replaces a line of command of Robot %d.\n", id, rbt[id].hd[cmd[ord].h]);
        k--;
    }
    else if (cmd[ord].type == "ACTIVATE")
    {
        printf("Robot %d activates Robot %d.\n", id, rbt[id].hd[cmd[ord].h]);
        k--;
        activate(rbt[id].hd[cmd[ord].h]);
    }
    if (rbt[id].hd[1] != id)
        for (int i = 1; i <= m; i++)
            if (cmd[rbt[rbt[id].hd[1]].act[i]].type == "TRIGGER")
                if (cmd[rbt[rbt[id].hd[1]].act[i]].con == cmd[ord].type ||
                    (cmd[rbt[rbt[id].hd[1]].act[i]].con == "TRIGGER" && f))
                {
                    run(rbt[id].hd[1], cmd[rbt[rbt[id].hd[1]].act[i]].sub, true);
                    break;
                }
    return;
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

100 1 300000
1 1
REPLACE 0 1 REPLACE 0 1 REPLACE 1 1 REPLACE 0 1 REPLACE 0 1 REPLACE 0 1 REPLACE 1 1 REPLACE 1 1 REPLACE 0 1 REPLACE 1 1 REPLACE 1 1 REPLACE 1 1 REPLACE 1 1 REPLACE 0 1 REPLACE 1 1 REPLACE 0 1 REPLACE 0 1 REPLACE 0 1 REPLACE 1 1 REPLACE 0 1 REPLACE 0 1 REPLACE 1 1 REPLACE 0 1 REPLACE...

output:

Robot 0 replaces a line of command of Robot 1.
Robot 1 replaces a line of command of Robot 2.
Robot 2 replaces a line of command of Robot 3.
Robot 3 replaces a line of command of Robot 4.
Robot 4 replaces a line of command of Robot 5.
Robot 5 replaces a line of command of Robot 6.
Robot 6 replaces a...

result: