QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#259497#6723. Grid with ArrowsZhou_JKWA 1ms3544kbC++232.1kb2023-11-20 23:35:132023-11-20 23:35:14

Judging History

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

  • [2023-11-20 23:35:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3544kb
  • [2023-11-20 23:35:13]
  • 提交

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;
    tot++;
    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(tot==295)
    {
        cout<<n<<","<<m<<",";
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cout<<s[get_id(i,j)]<<",";
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cout<<a[get_id(i,j)]<<",";
        cout<<cnt;
        exit(0);
    }
            if(cnt==n*m) cout<<"Yes\n";
            else cout<<"No\n";
            return;
        }
    cnt=0;
    dfs(1);
    if(tot==295)
    {
        cout<<n<<","<<m<<",";
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cout<<s[get_id(i,j)]<<",";
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            cout<<a[get_id(i,j)]<<",";
        cout<<cnt;
        exit(0);
    }
    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: 1ms
memory: 3412kb

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: 1ms
memory: 3544kb

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 output format YES or NO expected, but 5,3,D,R,D,D,D,U,U,R,L,R,U,U,D,...,2,4,3,1,1,1,1,2,2,3,2,4,1,1,15 found [295th token]