QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#499682#6723. Grid with ArrowsUmokWA 2ms7292kbC++201.8kb2024-07-31 17:00:082024-07-31 17:00:10

Judging History

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

  • [2024-07-31 17:00:10]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:7292kb
  • [2024-07-31 17:00:08]
  • 提交

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];
int f[N];
int n, m, d[N];
int find(int x)
{
    return f[x] == x ? f[x] : f[x] = find(f[x]);
}
void merge(int x, int y, int x_, int y_)
{
    int s1 = (x - 1) * m + y, s2 = (x_ - 1) * m + y_;
    int u = find(s1), v = find(s2);
    if (u != v)
        f[v] = u;
}

void solve()
{
    cin >> n >> m;
    int ans = n * m;
    for (int i = 1; i <= n; i++)
    {
        ar[i].clear();
        cin >> mp[i];
        mp[i] = " " + mp[i];
    }
    for (int i = 1; i <= ans; i++)
        f[i] = i;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            int x;
            scanf("%d", &x);
            int ch = (int)mp[i][j], p, q;
            if (ch == 117)
                p = i - x, q = j;
            else if (ch == 100)
                p = i + x, q = j;
            else if (ch == 108)
                p = i, q = j - x;
            else
                p = i, q = j + x;
            if (p < 1 || q < 1 || p > n || q > m)
                continue;
            merge(i, j, p, q);
            d[(p - 1) * m + q]++;
        }
    }

    int x = find(1);
    for (int i = 2; i <= ans; i++)
    {
        if (find(i) != x)
        {
            puts("No");
            return;
        }
    }
    int res = 0;
    for (int i = 1; i <= ans; i++)
    {
        if (!d[i])
            res++;
        if (res > 1)
        {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}
signed main()
{
    int tcase;
    cin >> tcase;
    while (tcase--)
        solve();
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 7292kb

input:

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

output:

No
No

result:

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