QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#499708 | #6723. Grid with Arrows | Umok | RE | 1ms | 3932kb | C++20 | 1.6kb | 2024-07-31 17:30:46 | 2024-07-31 17:30:46 |
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
string mp[N];
int ar[N][N], f[N];
bool st[N];
int n, m, ans;
int xx(int x, int y)
{
return (x - 1) * m + y;
}
int dfs(int x, int y, int deep)
{
if (st[xx(x, y)])
return 0;
f[xx(x, y)] = 1;
if (deep == ans)
{
return 1;
}
int a = x, b = y;
if (mp[x][y] == 'u')
a -= ar[x][y];
else if (mp[x][y] == 'r')
b += ar[x][y];
else if (mp[x][y] == 'd')
a += ar[x][y];
else
b -= ar[x][y];
if (a < 1 || a > n || b < 0 || b > m)
return 0;
st[xx(x, y)] = 1;
if (dfs(a, b, deep + 1))
return 1;
st[xx(x, y)] = 0;
return 0;
}
void solve()
{
cin >> n >> m;
ans = n * m;
for (int i = 1; i <= ans; i++)
f[i] = 0;
for (int i = 1; i <= n; i++)
st[i] = 0;
for (int i = 1; i <= n; i++)
{
cin >> mp[i];
mp[i] = " " + mp[i];
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
scanf("%lld", &ar[i][j]), f[i] = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
{
if (f[xx(i, j)])
continue;
bool z = dfs(i, j, 1);
if (z)
{
cout << "Yes" << endl;
return;
}
}
cout << "No" << endl;
}
signed main()
{
int tcase;
cin >> tcase;
while (tcase--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3932kb
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 No No Yes No No No No Yes No No No No No No No No Yes No No No Yes No No No No No Yes No No No No No No No No No No Yes No Yes No No No No No No No No No No No No Yes No No No No No No Yes No No No No No No No Yes No No No No No No No No No No No No Yes No Yes No Yes No No Yes Yes No No No No...