QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#259480 | #6723. Grid with Arrows | Zhou_JK | RE | 0ms | 3580kb | C++23 | 1.6kb | 2023-11-20 23:22:09 | 2023-11-20 23:22:10 |
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;
}
int tot;
void solve()
{
tot++;
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;
}
if(tot==5) exit(1);
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
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