QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#291169 | #2345. Karel the Robot | MoRanSky | AC ✓ | 344ms | 66768kb | C++23 | 3.1kb | 2023-12-26 05:11:56 | 2023-12-26 05:11:57 |
Judging History
answer
// Skyqwq
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char Dir[4] = { 'n', 'w', 's', 'e' };
int dx[4] = { -1, 0, 1, 0 };
int dy[4] = { 0, -1, 0, 1 };
const int N = 41, M = 26, S = 105;
int pos[200];
struct Node {
int x, y, d;
} f[N][N][4][M];
int n, m, t, q;
char g[N][N], ord[M][S], len[M], s[S], op[3];
bool vis[N][N][4][M];
bool inline check(Node v, char c) {
if (c == 'b') {
int nx = v.x + dx[v.d], ny = v.y + dy[v.d];
return nx < 1 || nx > n || ny < 1 || ny > m || g[nx][ny] == '#';
} else return pos[c] == v.d;
}
Node dp(int x, int y, int d, int c);
Node inline work(Node v, char *s, int len) {
// puts("Dmytxdy");
// printf("%d %d %c\n", v.x, v.y, Dir[v.d]);
// for (int i = 1; i <= len; i++) putchar(s[i]);
// puts("");
if (len <= 0) return v;
if (s[1] == 'm') {
int nx = v.x + dx[v.d], ny = v.y + dy[v.d];
if (nx >= 1 && nx <= n && ny >= 1 && ny <= m && g[nx][ny] == '.')
v.x = nx, v.y = ny;
v = work(v, s + 1, len - 1);
} else if (s[1] =='l') {
v.d = (v.d + 1) % 4;
v = work(v, s + 1, len - 1);
} else if (s[1] >= 'A' && s[1] <= 'Z') {
v = dp(v.x, v.y, v.d, s[1] - 'A');
if (v.x == -1) return v;
v = work(v, s + 1, len - 1);
} else if (s[1] == 'i') {
int L1 = 4, R1 = 3, cnt = 1;
while (!(cnt == 1 && s[R1 + 1] == ')')) {
R1++;
if (s[R1] == '(') cnt++;
else if (s[R1] == ')') cnt--;
}
int L2 = R1 + 3, R2 = R1 + 2; cnt = 1;
while (!(cnt == 1 && s[R2 + 1] == ')')) {
R2++;
if (s[R2] == '(') cnt++;
else if (s[R2] == ')') cnt--;
}
if (check(v, s[2])) {
v = work(v, s + L1 - 1, R1 - L1 + 1);
} else v = work(v, s + L2 - 1, R2 - L2 + 1);
if (v.x == -1) return v;
v = work(v, s + R2 + 1, len - (R2 + 1));
} else if (s[1] == 'u') {
int L1 = 4, R1 = 3, cnt = 1;
while (!(cnt == 1 && s[R1 + 1] == ')')) {
R1++;
if (s[R1] == '(') cnt++;
else if (s[R1] == ')') cnt--;
}
bool st[N][N][4];
memset(st, 0, sizeof st);
while (!check(v, s[2])) {
if (st[v.x][v.y][v.d]) { return (Node) { -1, 0, 0 } ; }
st[v.x][v.y][v.d] = true;
v = work(v, s + L1 - 1, R1 - L1 + 1);
if (v.x == -1) return v;
}
v = work(v, s + R1 + 1, len - (R1 + 1));
}
return v;
}
Node dp(int x, int y, int d, int c) {
Node &v = f[x][y][d][c];
if (v.x) return v;
if (vis[x][y][d][c]) { v.x = -1; return v; }
vis[x][y][d][c] = true;
v = work((Node) { x, y, d } , ord[c], len[c]);
vis[x][y][d][c] = false;
return v;
}
int main() {
pos['n'] = 0, pos['w'] = 1, pos['s'] = 2, pos['e'] = 3;
scanf("%d%d%d%d", &n, &m, &t, &q);
for (int i = 1; i <= n; i++) scanf("%s", g[i] + 1);
for (int i = 1; i <= t; i++) {
scanf("%s", s + 1); int l = strlen(s + 1);
int ch = s[1] - 'A';
len[ch] = l - 2;
for (int i = 1; i <= l - 2; i++) ord[ch][i] = s[i + 2];
}
while (q--) {
int x, y; scanf("%d%d%s%s", &x, &y, op, s + 1); int l = strlen(s + 1);
int d = pos[*op];
Node v = work((Node) { x, y, d }, s, l);
if (v.x == -1) puts("inf");
else printf("%d %d %c\n", v.x, v.y, Dir[v.d]);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 4104kb
Test #2:
score: 0
Accepted
time: 0ms
memory: 3876kb
Test #3:
score: 0
Accepted
time: 0ms
memory: 4040kb
Test #4:
score: 0
Accepted
time: 0ms
memory: 3948kb
Test #5:
score: 0
Accepted
time: 0ms
memory: 3868kb
Test #6:
score: 0
Accepted
time: 1ms
memory: 4936kb
Test #7:
score: 0
Accepted
time: 23ms
memory: 7280kb
Test #8:
score: 0
Accepted
time: 7ms
memory: 66768kb
Test #9:
score: 0
Accepted
time: 344ms
memory: 8248kb
Test #10:
score: 0
Accepted
time: 1ms
memory: 3904kb
Test #11:
score: 0
Accepted
time: 0ms
memory: 3936kb
Test #12:
score: 0
Accepted
time: 0ms
memory: 3904kb
Test #13:
score: 0
Accepted
time: 0ms
memory: 4048kb
Test #14:
score: 0
Accepted
time: 0ms
memory: 3904kb
Test #15:
score: 0
Accepted
time: 2ms
memory: 5680kb
Test #16:
score: 0
Accepted
time: 3ms
memory: 6160kb
Test #17:
score: 0
Accepted
time: 328ms
memory: 7964kb
Test #18:
score: 0
Accepted
time: 331ms
memory: 7984kb
Test #19:
score: 0
Accepted
time: 3ms
memory: 6596kb
Test #20:
score: 0
Accepted
time: 54ms
memory: 7364kb