QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#499478 | #6723. Grid with Arrows | Railgun2334 | RE | 0ms | 11712kb | C++20 | 2.4kb | 2024-07-31 14:46:31 | 2024-07-31 14:46:32 |
Judging History
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;
}
}
Details
Tip: Click on the bar to expand more detailed information
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 ...