QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#499531#6723. Grid with ArrowsbuzhijingdiWA 50ms5832kbC++142.2kb2024-07-31 15:24:372024-07-31 15:24:38

Judging History

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

  • [2024-07-31 15:24:38]
  • 评测
  • 测评结果:WA
  • 用时:50ms
  • 内存:5832kb
  • [2024-07-31 15:24:37]
  • 提交

answer

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

int n,m;

void solve()
{
    cin>>n>>m;
    int vis[n + 10]={0};
   // for(int i=1;i<=n;++i) a[i]=0;
    char s[n + 5][m + 5];
    int p[n + 5][m + 5];
    bool v[n + 5][m + 5];
    for(int i=1;i<=n;++i)
        for(int j=1;j<=m;++j) v[i][j]=false;

    int cnt=0,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];
            if(s[i][j]=='u')
            {
                if(i - p[i][j] >= 1) sum++,v[i - p[i][j]][j]=true;;
                if(i - p[i][j] >= 1 &&  s[i - p[i][j]][j] != 'u' && s[i - p[i][j]][j]!='d')
                {
                    if(!vis[i - p[i][j]]) cnt++;
                    vis[i - p[i][j]]++;
                }
            }
            else if(s[i][j]=='d')
            {
                if(i + p[i][j] <= n) sum++,v[i + p[i][j]][j]=true;;
                if(i + p[i][j] <= n &&  s[i + p[i][j]][j] != 'u' && s[i + p[i][j]][j]!='d')
                {
                    if(!vis[i + p[i][j]]) cnt++;
                    vis[i + p[i][j]]++;
                }
            }
        }

    if(cnt != n)
    {
        cout<<"No"<<'\n';
        return ;
    } 
  // cout<<sum<<'\n';
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            if(s[i][j]=='r' && p[i][j] + j <=m && !v[i][j + p[i][j]])
            {
                //cout<<":"<<i<<j<<'\n';
                v[i][j + p[i][j]]=1;
                sum++;
            }
            else if(s[i][j]=='l' && j  - p[i][j] >= 1 && !v[i][j - p[i][j]])
            {
                //cout<<":"<<i<<j<<'\n';
                v[i][j - p[i][j]]=1;
                sum++;
            }
        }
    }
    //cout<<sum<<'\n';
    if(sum >= n*m - 1) cout<<"Yes"<<'\n';
    else cout<<"No"<<'\n';
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int _ = 1;  cin>>_;
    while (_--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 50ms
memory: 5832kb

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

result:

wrong answer expected NO, found YES [2nd token]