QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#499613#6723. Grid with ArrowsbuzhijingdiWA 85ms10788kbC++142.0kb2024-07-31 16:19:262024-07-31 16:19:26

Judging History

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

  • [2024-07-31 16:19:26]
  • 评测
  • 测评结果:WA
  • 用时:85ms
  • 内存:10788kb
  • [2024-07-31 16:19:26]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e6 + 9;
const int M = 1e3 + 9;
const int mod = 1e9 + 7;
#define eps 1e-5
#define inf 2e18

int n,m; 
int fa[N];
int find(int x)
{
    return fa[x]=(fa[x]==x?x:find(fa[x]));
}
bool check(int x,int y)
{
    return x>=1 && y>=1 && x<=n && y<=m;
}

void dfs(int x,int y,vector<vector<char>> &s, vector<vector<int>> &a)
{
    int px=x,py=y;//pre

    if(s[x][y]=='u')  x -= a[x][y];
    else if(s[x][y]=='d') x += a[x][y];
    else if(s[x][y]=='l') y -= a[x][y];
    else if(s[x][y]=='r') y += a[x][y];
    
    if(check(x,y))
    {
        int fx=find((px - 1) * m + py),fy = find((x - 1) * m + y);
        if(fx != fy)
        {
            fa[fy] = fx;
            dfs(x,y,s,a);
        }
    }
}
void solve()
{
    cin>>n>>m;
    for(int i=1;i<= (n-1) * m + m + 10; i++) fa[i]=i;

    vector<vector<int>> p(n+10);
    vector<vector<char>> s(n+10);
    for(int i=1;i<=n;i++)
    {
        p[i].resize(m+10);
        s[i].resize(m+10);
    }


    int sum=0;
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)   cin>>s[i][j];
        
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j)    cin>>p[i][j];

    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++) dfs(i,j,s,p);

    int cnt=0;
    for(int i=1;i<=n*m;++i) if(fa[i]==i) cnt++;
    if(cnt>=2) 
    {
        cout<<"No"<<'\n';
        return ;
    }


    int rt=find(1);
    //cout<<"  "<<rt<<'\n';
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(find((i-1)*m+j) != rt)
            {
                cout<<"No"<<'\n';
                return;
            }
    
    cout<<"Yes"<<'\n';
}
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;  cin>>_;
    while (_--) solve();
    return 0;
}
/*
2
3 4
drrd
ruld
udrl
1 1 1 1
2 1 1 1
2 100 1 1
3 4
drrd
ruld
udll
1 1 1 1
2 1 1 1
2 100 1 1
*/ 

詳細信息

Test #1:

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

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: 85ms
memory: 10788kb

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

result:

wrong answer expected NO, found YES [43rd token]