QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#259488#6723. Grid with ArrowsZhou_JKWA 56ms4740kbC++231.7kb2023-11-20 23:30:052023-11-20 23:30:06

Judging History

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

  • [2023-11-20 23:30:06]
  • 评测
  • 测评结果:WA
  • 用时:56ms
  • 内存:4740kb
  • [2023-11-20 23:30:05]
  • 提交

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()
{
    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)];
            else exit(1);
            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;
        }
    cnt=0;
    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;
}

/*
1
5 3
d r d d d
u u r l r
u u d u l
3 2 4 3 1
1 1 1 2 2
3 2 4 1 1
*/

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3408kb

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: 56ms
memory: 4740kb

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

result:

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