QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#499623#6723. Grid with ArrowsRailgun2334WA 8ms3972kbC++203.8kb2024-07-31 16:24:552024-07-31 16:24:56

Judging History

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

  • [2024-07-31 16:24:56]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:3972kb
  • [2024-07-31 16:24:55]
  • 提交

answer

#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cstdio>
#include <cmath>
#include <fstream>
#define opeen freopen("in.txt", "r", stdout);
// #define int long long
using namespace std;
const int N = 1e5 + 10, M = 1e6 + 10, MOD = 1e9 + 7;
int n, m;
bool flag = 0;
void dfs(int x, int y, vector<vector<int>> a, int num, vector<vector<bool>> f, vector<vector<char>> s)
{
    // cout<<x<<' '<<y<<' '<<num<<'\n';
    if (num >= n * m)
    {
        flag = 1;
        return;
    }
    if (s[x][y] == 'r')
    {
        int xx = x, yy = y + a[x][y];
        if (xx >= 1 && xx <= n && yy >= 1 && yy <= m)
        {
            if (f[xx][yy] != 0)
                return;
            f[xx][yy] = 1;
            dfs(xx, yy, a, num + 1, f, s);
        }
    }
    else if (s[x][y] == 'l')
    {
        int xx = x, yy = y - a[x][y];
        if (xx >= 1 && xx <= n && yy >= 1 && yy <= m)
        {
            if (f[xx][yy] != 0)
                return;
            f[xx][yy] = 1;
            dfs(xx, yy, a, num + 1, f, s);
        }
    }
    else if (s[x][y] == 'd')
    {
        int xx = x + a[x][y], yy = y;
        if (xx >= 1 && xx <= n && yy >= 1 && yy <= m)
        {
            if (f[xx][yy] != 0)
                return;
            f[xx][yy] = 1;
            dfs(xx, yy, a, num + 1, f, s);
        }
    }
    else
    {
        int xx = x - a[x][y], yy = y;
        if (xx >= 1 && xx <= n && yy >= 1 && yy <= m)
        {
            if (f[xx][yy] != 0)
                return;
            f[xx][yy] = 1;
            dfs(xx, yy, a, num + 1, f, s);
        }
    }
}
void solove()
{
    cin >> n >> m;
    vector<vector<int>> a(n + 1, vector<int>(m + 1));
    vector<vector<bool>> f(n + 1, vector<bool>(m + 1));
    vector<vector<char>> s(n + 1, vector<char>(m + 1));
    for (int i = 1; i <= n; i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>s[i][j];
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> a[i][j];
        }
    }
    vector<pair<int, int>> op;
    vector<vector<bool>> st(n + 1, vector<bool>(m + 1));
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            int x = i, y = j;
            if (s[i][j] == 'r')
            {
                x = i, y = j + a[i][j];
            }
            else if (s[i][j] == 'l')
            {
                x = i, y = j - a[i][j];
            }
            else if (s[i][j] == 'd')
            {
                x = i + a[i][j], y = j;
            }
            else
            {
                x = i - a[i][j], y = j;
            }
            if (x >= 1 && x <= n && y >= 1 && y <= m)
            {
                st[x][y] = 1;
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (st[i][j] == 1)
                continue;
            op.push_back({i, j});
            if (op.size() >= 2)
            {
                cout << "No\n";
                return;
            }
        }
    }
    if (op.size() == 0)
        cout << "Yes\n";
    else if (op.size() == 1)
    {
        flag = 0;
        f[op[0].first][op[0].second] = 1;
        dfs(op[0].first, op[0].second, a, 1, f, s);
        if (flag == 1)
            cout << "Yes\n";
        else
            cout << "No\n";
    }
    else
        cout << "No\n";
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TT = 1;
    cin >> TT;
    while (TT--)
    {
        solove();
        if(TT==500)break;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3564kb

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: 8ms
memory: 3972kb

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

result:

wrong answer expected NO, found YES [12th token]