QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#788342 | #2345. Karel the Robot | billf | WA | 1ms | 4172kb | C++14 | 4.1kb | 2024-11-27 16:36:44 | 2024-11-27 16:36:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int B = 500;
bool 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)
return 0;
if (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 dfs(bot sta, string opt, int ty = 26)
{
int x = sta.x, y = sta.y, w = sta.w;
if (w == -1)
return sta;
if (ty < 26 && vis[x][y][w][ty])
return INF;
if (ty < 26)
vis[x][y][w][ty] = 1;
int len = opt.size(), cnt, pos, ps1, sum;
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)), 26);
}
else
{
if (pos + 2 <= ps1)
sta = dfs(sta, opt.substr(pos + 2, ps1 - (pos + 2)), 26);
}
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;
}
}
while (!sta.con(opt[i + 1]))
{
cnt++;
sta = dfs(sta, opt.substr(i + 3, pos - (i + 3)), 26);
if (cnt > B)
return INF;
}
i = pos;
}
else if (opt[i] == 'l')
sta.l();
else if (opt[i] == 'm')
sta.m();
else
sta = dfs(sta, fnc[opt[i] - 'A'], 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);
}
while (q--)
{
memset(vis, 0, sizeof vis);
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: 1ms
memory: 4112kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 4172kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 3888kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 4116kb
Test #5:
score: 0
Accepted
time: 1ms
memory: 3884kb
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 4116kb