QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#500446#6723. Grid with ArrowsUmokAC ✓421ms8468kbC++201.9kb2024-08-01 11:56:102024-08-01 11:56:11

Judging History

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

  • [2024-08-01 11:56:11]
  • 评测
  • 测评结果:AC
  • 用时:421ms
  • 内存:8468kb
  • [2024-08-01 11:56:10]
  • 提交

answer

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

void dfs(int x, int y)
{
    if (st[(x - 1) * m + y])
        return;
    f[(x - 1) * m + y] = 1;
    st[(x - 1) * m + y] = 1;
    int xx = x, yy = y;

    if (mp[(x - 1) * m + y] == 'r')
        yy += ar[(x - 1) * m + y];
    else if (mp[(x - 1) * m + y] == 'd')
        xx += ar[(x - 1) * m + y];
    else if (mp[(x - 1) * m + y] == 'l')
        yy -= ar[(x - 1) * m + y];
    else
        xx -= ar[(x - 1) * m + y];

    if (xx < 1 || xx > n || yy < 1 || yy > m)
        return;
    dfs(xx, yy);
    return;
}

void solve()
{
    cin >> n >> m;
    ans = n * m;
    memset(ar, 0, sizeof ar);
    memset(f, 0, sizeof f);
    memset(st, 0, sizeof st);

    for (int i = 1; i <= n; i++)
        scanf("%s", mp + 1 + (i - 1) * m);

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            int x;
            cin >> x;
            ar[(i - 1) * m + j] = x;
        }

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            if (!f[(i - 1) * m + j])
            {
                for (int i = 1; i <= ans; i++)
                    st[i] = 0;
                dfs(i, j);
                bool is = 1;
                for (int t = 1; t <= ans; t++)
                    if (st[t] == 0)
                    {
                        is = 0;
                        break;
                    }
                if (is)
                {
                    cout << "Yes" << endl;
                    return;
                }
            }
        }

    cout << "No" << endl;
}
signed main()
{

    int tcase;
    cin >> tcase;
    while (tcase--)
        solve();
    return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 421ms
memory: 8468kb

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
Yes
Yes
Yes
Yes
No
No
No
Yes
Yes
No
Yes
No
Yes
No
No
No
Yes
Yes
No
Yes
Yes
No
Yes
No
No
Yes
No
No
Yes
Yes
Yes
No
No
Yes
Yes
Yes
No
Yes
No
Yes
No
Yes
Yes
No
Yes
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
Yes
No
No
Yes
Yes
No
No
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Y...

result:

ok 1109 token(s): yes count is 602, no count is 507