QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#500401#6723. Grid with ArrowsUmokRE 2ms7828kbC++201.7kb2024-08-01 11:13:502024-08-01 11:13:51

Judging History

你现在查看的是最新测评结果

  • [2024-08-01 11:13:51]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:7828kb
  • [2024-08-01 11:13:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
const int N = 1e5 + 5;
#define int long long
typedef pair<int, int> PII;
#define MAX LONG_LONG_MAX
string mp[N];
int st[N], ar[N], f[N];
int n, m, ans;

int dfs(int x, int y, int deep)
{
    if (deep == ans)
        return 1;
    if (st[(x - 1) * n + y])
        return 0;
    f[(x - 1) * n + y] = 1;
    st[(x - 1) * n + y] = 1;
    int xx = x, yy = y;
    if (mp[x][y] == 'r')
        yy += ar[(x - 1) * n + y];
    else if (mp[x][y] == 'd')
        xx += ar[(x - 1) * n + y];
    else if (mp[x][y] == 'l')
        yy -= ar[(x - 1) * n + y];
    else
        xx -= ar[(x - 1) * n + y];

    if (xx < 0 || xx > n || yy < 0 || yy > m)
        return 0;
    if (dfs(xx, yy, deep + 1))
        return 1;
    st[(x - 1) * n + y] = 0;
    return 0;
}

void solve()
{
    cin >> n >> m;
    ans = n * m;
    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++)
        {
            int x;
            cin >> x;
            ar[(i - 1) * n + j] = x;
            f[(i - 1) * n + j] = 0;
            st[(i - 1) * n + j] = 0;
        }
    }

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            if (f[(i - 1) * n + j])
                continue;
            if (dfs(i, j, 1))
            {
                cout << "Yes" << endl;
                return;
            }
        }

    cout << "No" << endl;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int tcase;
    cin >> tcase;
    while (tcase--)
        solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 7828kb

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:


result: