QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#413319#6723. Grid with Arrowsyujie3AC ✓56ms37108kbC++201.3kb2024-05-17 12:14:262024-05-17 12:14:27

Judging History

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

  • [2024-05-17 12:14:27]
  • 评测
  • 测评结果:AC
  • 用时:56ms
  • 内存:37108kb
  • [2024-05-17 12:14:26]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define endl '\n'

using namespace std;

const int N = 1e6 + 7;
int n,m;
string s[N];

void solve(){
    cin >> n >> m;
    vector<int> g(n * m,-1);
    vector<int> d(n * m);
    for(int i = 0;i < n;i ++) cin >> s[i];
    for(int i = 0;i < n;i ++){
        for(int j = 0;j < m;j ++){
            int dis; cin >> dis; 
            int pos = i * m + j;
            if(s[i][j] == 'r' && j + dis < m) g[pos] = pos + dis,d[pos + dis] ++;
            if(s[i][j] == 'l' && j - dis >= 0) g[pos] = pos - dis,d[pos - dis] ++;
            if(s[i][j] == 'u' && i - dis >= 0) g[pos] = pos - dis * m,d[pos - dis * m] ++;
            if(s[i][j] == 'd' && i + dis < n) g[pos] = pos + dis * m,d[pos + dis * m] ++; 
        }
    }
    int root = 0;
    for(int i = 0;i < n * m;i ++){
        if(!d[i]){
            root = i;
            break;
        }
    } 
    vector<int> st(n * m);
    for(int i = 0;i < n * m + 100 && root != -1;i ++){
        st[root] = 1;
        root = g[root];
    }
    if(count(st.begin(),st.end(),1) != n * m) cout << "No" << endl;
    else cout << "Yes" << endl; 
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int t; cin >> t;
    while(t --){
        solve();
    }
    return 0;
} 

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 34860kb

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: 0
Accepted
time: 56ms
memory: 37108kb

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:

ok 1109 token(s): yes count is 602, no count is 507