QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#499450 | #6723. Grid with Arrows | Umok | RE | 1ms | 9952kb | C++20 | 1.4kb | 2024-07-31 14:23:49 | 2024-07-31 14:23:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
const int N = 1e4 + 5;
#define int long long
typedef pair<int, int> PII;
#define MAX LONG_LONG_MAX
char mp[N][N];
int ar[N][N], f[N][N];
bool st[N][N];
int n, m;
int dfs(int x, int y)
{
if (x > n || x < 1 || y > m || y < 1)
return 0;
if (f[x][y])
return f[x][y] + 1;
if (st[x][y])
return 1;
st[x][y] = 1;
int xx = x, yy = y;
if (mp[x][y] == 'r')
yy += ar[x][y];
else if (mp[x][y] == 'd')
xx += ar[x][y];
else if (mp[x][y] == 'l')
yy -= ar[x][y];
else
xx -= ar[x][y];
f[x][y] = dfs(xx, yy) + 1;
st[x][y] = 0;
return f[x][y];
}
void solve()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
scanf("%s", mp[i] + 1);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
scanf("%lld", &ar[i][j]), f[i][j] = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
{
if (f[i][j])
continue;
dfs(i, j);
}
int ans = m * n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (f[i][j] == ans)
{
puts("Yes");
return;
}
puts("No");
}
signed main()
{
int tcase;
cin >> tcase;
while (tcase--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 9952kb
input:
2 2 3 rdd url 2 1 1 1 1 2 2 2 rr rr 1 1 1 1
output:
Yes No
result:
ok 2 token(s): yes count is 1, no count is 1
Test #2:
score: -100
Runtime Error
input:
1109 5 8 rddddldl drruludl rrldrurd urrrlluu uurrulrl 4 4 1 2 4 3 1 6 1 3 5 1 1 1 3 6 2 4 1 1 2 1 1 1 2 3 4 2 4 3 3 3 4 1 1 2 2 5 1 5 7 9 rdrddrdll urrdruldl ruullrulu drrlrlddl rrrdddlll ruulururl ruurrlluu 7 1 1 1 2 1 2 3 6 1 7 3 1 3 1 2 1 8 2 2 1 2 4 3 1 2 2 2 2 4 1 1 5 3 3 1 3 4 6 1 2 1 2 7 7 6 ...
output:
Yes No Yes No Yes No No Yes Yes Yes No No No Yes Yes No Yes No Yes No No No Yes Yes No Yes Yes No No No No Yes No No Yes No No No Yes Yes Yes Yes No Yes No No No Yes Yes No Yes No Yes No Yes No No No Yes No Yes Yes Yes Yes No Yes Yes No Yes Yes No No No Yes No No Yes Yes No No Yes Yes Yes Yes Yes No...