QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#499478#6723. Grid with ArrowsRailgun2334RE 0ms11712kbC++202.4kb2024-07-31 14:46:312024-07-31 14:46:32

Judging History

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

  • [2024-07-31 14:46:32]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:11712kb
  • [2024-07-31 14:46:31]
  • 提交

answer

#include<bits/stdc++.h>
#define endl "\n"
#define int long long
#define x first
#define y second
#define MAXN 1005
#define pii pair<int,int>
using namespace std;
int n,m,p,x,y,T;
pii fa[MAXN][MAXN],rk[MAXN][MAXN];
bool flag[1005][1005];
string s[100005];
int a[1005][1005];
pii fid(char str,int x,int y)
{
    if(flag[x][y])
    {
        return fa[x][y];
    }
    flag[x][y]=true;
    if(str=='r')
    {
        if(y+a[x][y]<=m)
        {
            return fa[x][y]=fid(s[x][y+a[x][y]],x,y+a[x][y]);
        }
        else
        {
            return {x,y};
        }
    }
    else if(str=='d')
    {
        if(x+a[x][y]<=n)
        {
             return fa[x][y]=fid(s[x+a[x][y]][y],x+a[x][y],y);
        }
        else
        {
            return {x,y};
        }
    }
    else if(str=='u')
    {
        if(x-a[x][y]>=1)
        {
             return fa[x][y]=fid(s[x-a[x][y]][y],x-a[x][y],y);
        }
        else
        {
            return {x,y};
        }
    }
    else if(str=='l')
    {
        if(y-a[x][y]>=1)
        {
             return fa[x][y]=fid(s[x][y-a[x][y]],x,y-a[x][y]);
        }
        else
        {
            return {x,y};
        }
    }
    return {x,y};
}
void solve()
{
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            fid(s[i][j],i,j);
        }
    }
}
signed main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(0);cout.tie(0);
    cin>>T;
    //init(n);
    while(T--)
    {
        cin>>n>>m;
        for(int i=1;i<=n;i++)
        {
            cin>>s[i];
            s[i]=' '+s[i];
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                cin>>a[i][j];
                fa[i][j]={i,j};
            }
        }
        solve();
        /*
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                cout<<fa[i][j].x<<" "<<fa[i][j].y<<endl;
            }
        }*/
        pii ans=fa[1][1];
        bool f=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(ans!=fa[i][j])
                {
                    f=1;
                    break;
                }
            }
            if(f==1)
                break;
        }
        if(f==1)
            cout<<"No"<<endl;
        else
            cout<<"Yes"<<endl;
    }
}

详细

Test #1:

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

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
Runtime Error

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

result: