QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#499460#6723. Grid with ArrowsUmokWA 1ms7956kbC++201.5kb2024-07-31 14:30:182024-07-31 14:30:19

Judging History

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

  • [2024-07-31 14:30:19]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7956kb
  • [2024-07-31 14:30:18]
  • 提交

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][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++)
    {
        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][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()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int tcase;
    cin >> tcase;
    while (tcase--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7956kb

input:

2
2 3
rdd
url
2 1 1
1 1 2
2 2
rr
rr
1 1
1 1

output:

No
Yes

result:

wrong answer expected YES, found NO [1st token]