QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#789159#2345. Karel the RobotbillfWA 235ms34648kbC++144.5kb2024-11-27 19:26:022024-11-27 19:26:02

Judging History

This is the latest submission verdict.

  • [2024-11-27 19:26:02]
  • Judged
  • Verdict: WA
  • Time: 235ms
  • Memory: 34648kb
  • [2024-11-27 19:26:02]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
int vis[45][45][4][27];
char a[45][45], tmp;
int way[4][2] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}};
int N, M, f, q;
bool ck(int x, int y)
{
    if (x < 1 || y < 1 || x > N || y > M || a[x][y] == '#')
        return 0;
    return 1;
}
char num_ch(int op)
{
    if (op == 0)
        return 'w';
    else if (op == 1)
        return 'n';
    else if (op == 2)
        return 'e';
    else if (op == 3)
        return 's';
    else
        return '#';
}
struct bot
{
    int x, y, w;
    bot(int _x = 0, int _y = 0, int _w = 0)
    {
        x = _x, y = _y, w = _w;
    }
    void in()
    {
        char op;
        cin >> x >> y >> op;
        if (op == 'w')
            w = 0;
        else if (op == 'n')
            w = 1;
        else if (op == 'e')
            w = 2;
        else if (op == 's')
            w = 3;
    }
    void out()
    {
        cout << x << ' ' << y << ' ' << num_ch(w) << '\n';
    }
    void m()
    {
        int _x = x + way[w][0], _y = y + way[w][1];
        if (ck(_x, _y))
            x = _x, y = _y;
    }
    void l()
    {
        w = !w ? w + 3 : w - 1;
    }
    bool con(char op)
    {
        if (op == 'b')
        {
            int _x = x + way[w][0], _y = y + way[w][1];
            return !ck(_x, _y);
        }
        else
            return num_ch(w) == op;
    }
} INF;
string fnc[26];
bot to[45][45][4][27];
bot dfs(bot, string);
bot solve(bot sta, int op)
{
    int x = sta.x, y = sta.y, w = sta.w;
    bot &fg = to[x][y][w][op];
    if (fg.x)
        return fg;
    if (vis[x][y][w][op])
        return fg = INF;
    if (fnc[op].empty())
        return fg = sta;
    vis[x][y][w][op] = 1;
    fg = dfs(sta, fnc[op]);
    vis[x][y][w][op] = 0;
    return fg;
}
bot dfs(bot sta, string opt)
{
    if (opt.empty())
        return sta;
    int x = sta.x, y = sta.y, w = sta.w;
    if (w == -1)
        return sta;
    int len = opt.size(), cnt, pos, ps1, sum;
    bool usd[45][45][4] = {0};
    for (int i = 0; i < len; i++)
    {
        if (opt[i] == 'i')
        {
            sum = cnt = 0;
            for (int j = i + 2; j < len; j++)
            {
                if (opt[j] == '(')
                    sum++;
                else if (opt[j] == ')')
                    sum--;
                if (!sum)
                {
                    if (cnt)
                    {
                        ps1 = j;
                        break;
                    }
                    cnt++;
                    pos = j;
                }
            }
            if (sta.con(opt[i + 1]))
            {
                if (i + 3 < pos)
                    sta = dfs(sta, opt.substr(i + 3, pos - (i + 3)));
            }
            else
            {
                if (pos + 2 < ps1)
                    sta = dfs(sta, opt.substr(pos + 2, ps1 - (pos + 2)));
            }
            i = ps1;
        }
        else if (opt[i] == 'u')
        {
            sum = cnt = 0;
            for (int j = i + 2; j < len; j++)
            {
                if (opt[j] == '(')
                    sum++;
                else if (opt[j] == ')')
                    sum--;
                if (!sum)
                {
                    pos = j;
                    break;
                }
            }
            if (i + 3 < pos)
            {
                memset(usd, 0, sizeof usd);
                while (!sta.con(opt[i + 1]))
                {
                    sta = dfs(sta, opt.substr(i + 3, pos - (i + 3)));
                    if (sta.w == -1 || usd[sta.x][sta.y][sta.w])
                        return INF;
                    usd[sta.x][sta.y][sta.w] = 1;
                }
            }
            i = pos;
        }
        else if (opt[i] == 'l')
            sta.l();
        else if (opt[i] == 'm')
            sta.m();
        else
            sta = solve(sta, opt[i] - 'A');
        if (sta.w == -1)
            return INF;
    }
    return sta;
}
int main()
{
    INF = bot(1, 1, -1);
    cin >> N >> M >> f >> q;
    for (int i = 1; i <= N; i++)
        scanf("%s", a[i] + 1);
    string opt;
    while (f--)
    {
        cin >> opt;
        fnc[opt[0] - 'A'] = opt.substr(2);
    }
    memset(vis, 0, sizeof vis);
    while (q--)
    {
        bot ans;
        ans.in();
        cin >> opt;
        ans = dfs(ans, opt);
        if (ans.w == -1)
            puts("inf");
        else
            ans.out();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 7180kb

Test #2:

score: 0
Accepted
time: 2ms
memory: 7100kb

Test #3:

score: 0
Accepted
time: 2ms
memory: 7312kb

Test #4:

score: 0
Accepted
time: 2ms
memory: 7128kb

Test #5:

score: 0
Accepted
time: 0ms
memory: 7068kb

Test #6:

score: 0
Accepted
time: 0ms
memory: 7320kb

Test #7:

score: 0
Accepted
time: 17ms
memory: 7248kb

Test #8:

score: 0
Accepted
time: 27ms
memory: 34648kb

Test #9:

score: 0
Accepted
time: 235ms
memory: 7364kb

Test #10:

score: 0
Accepted
time: 1ms
memory: 7360kb

Test #11:

score: 0
Accepted
time: 1ms
memory: 7376kb

Test #12:

score: 0
Accepted
time: 2ms
memory: 7092kb

Test #13:

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