QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#259479 | #6723. Grid with Arrows | Zhou_JK | WA | 44ms | 4920kb | C++23 | 1.5kb | 2023-11-20 23:21:35 | 2023-11-20 23:21:35 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
const int N=100005;
int n,m;
char s[N];
int a[N];
int get_id(int x,int y)
{
return (x-1)*m+y;
}
int to[N];
int deg[N];
bool vis[N];
int cnt;
void dfs(int u)
{
vis[u]=true;
cnt++;
int v=to[u];
if(!vis[v]) dfs(v);
return;
}
void solve()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>s[get_id(i,j)];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>a[get_id(i,j)];
fill(deg+1,deg+n*m+1,0);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
int x=i,y=j;
if(s[get_id(i,j)]=='u') x=i-a[get_id(i,j)],y=j;
else if(s[get_id(i,j)]=='d') x=i+a[get_id(i,j)],y=j;
else if(s[get_id(i,j)]=='l') x=i,y=j-a[get_id(i,j)];
else if(s[get_id(i,j)]=='r') x=i,y=j+a[get_id(i,j)];
if(x<1||x>n||y<1||y>m) continue;
to[get_id(i,j)]=get_id(x,y);
deg[get_id(x,y)]++;
}
fill(vis+1,vis+n*m+1,false);
for(int i=1;i<=n*m;i++)
if(deg[i]==0)
{
cnt=0;
dfs(i);
if(cnt==n*m) cout<<"Yes\n";
else cout<<"No\n";
return;
}
dfs(1);
if(cnt==n*m) cout<<"Yes\n";
else cout<<"No\n";
return;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int T;
cin>>T;
while(T--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3392kb
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: 44ms
memory: 4920kb
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 Yes No No No No No No No No No No No No No No No No No No Yes Yes No Yes No No Yes No No No Yes Yes No No No No No No No No Yes No No No No No No No No No Yes 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 Yes No No No No No No No No Yes Yes N...
result:
wrong answer expected YES, found NO [5th token]