QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#499658#6723. Grid with ArrowsUmokWA 76ms21420kbC++202.5kb2024-07-31 16:41:152024-07-31 16:41:16

Judging History

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

  • [2024-07-31 16:41:16]
  • 评测
  • 测评结果:WA
  • 用时:76ms
  • 内存:21420kb
  • [2024-07-31 16:41:15]
  • 提交

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];
vector<int> ar[N], f;
vector<int> st[N];
int n, m, din[N];
int finds(int x)
{
    if (f[x] == x)
        return x;
    return f[x] = finds(f[x]);
}
PII find(int x, int y)
{
    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];
    if (xx < 1 || xx > n || yy < 0 || yy > m)
        return {0, 0};
    return {xx, yy};
}

void solve()
{
    cin >> n >> m;
    int ans = n * m;
    f.clear();
    for (int i = 1; i <= n; i++)
    {
        mp[i] = "";
        ar[i].clear();
        st[i].clear();
    }
    for (int i = 1; i <= n; i++)
    {
        cin >> mp[i];
        mp[i] = " " + mp[i];
    }
    for (int i = 1; i <= n; i++)
    {
        ar[i].push_back(0);
        f.push_back(0);
        st[i].push_back(0);
        for (int j = 1; j <= m; j++)
        {
            int x;
            cin >> x;
            ar[i].push_back(x);
            f.push_back(0);
            st[i].push_back(0);
        }
    }
    st[0].push_back(0);

    for (int i = 1; i <= ans; i++)
        f[i] = i;

    int num = 1;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            st[i][j] = num++;

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            auto a = find(i, j);
            int x = a.first, y = a.second;
            int _ = f[st[i][j]], __ = f[st[x][y]];
            if (_ == __ || _ < 1 || __ < 1)
                continue;
            din[__]++;
            f[finds(__)] = finds(_);
        }
    int x = finds(1);
    for (int i = 2; i <= ans; i++)
    {
        if (finds(i) != x)
        {
            puts("No");
            return;
        }
    }
    int in0 = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            if (din[st[i][j]] == 0)
                in0++;
            if (in0 > 1)
            {
                cout << "No" << endl;
                return;
            }
        }
    cout << "Yes" << 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: 6784kb

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
Wrong Answer
time: 76ms
memory: 21420kb

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

result:

wrong answer expected NO, found YES [2nd token]