QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214154#6723. Grid with Arrowsyyyyy3WA 157ms13692kbC++141.8kb2023-10-14 17:33:572023-10-14 17:33:57

Judging History

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

  • [2023-10-14 17:33:57]
  • 评测
  • 测评结果:WA
  • 用时:157ms
  • 内存:13692kb
  • [2023-10-14 17:33:57]
  • 提交

answer

#include<iostream>
#include<vector>
#include<numeric>
#include<string>
#include<queue>
#include<algorithm>



using namespace std;

const int maxn = 1e5;

string s[maxn];

struct dsu {
  vector<size_t> pa, size;

  explicit dsu(size_t size_) : pa(size_), size(size_, 1) {
    iota(pa.begin(), pa.end(), 0);
  }
    
  size_t find(size_t x) { return pa[x] == x ? x : pa[x] = find(pa[x]); }


  void unite(size_t x, size_t y) {
    x = find(x), y = find(y);
    if (x == y) return;
    if (size[x] < size[y]) swap(x, y);
    pa[y] = x;
    size[x] += size[y];
  }
};

int n,m;

bool check(int x,int y){
        if( x>=n || x<0)return false;
        if( y>=m || y<0)return false;
        return true;
}

void slove(){
    cin>>n>>m;
    for(int i = 0;i<n;i++){
        cin>>s[i];
    }
    vector<vector<int> >a(n,vector<int>(m));
    vector<vector<int> >b(n,vector<int>(m));
    dsu d(m*n + 10);
    int pos = 1;
    for(int i = 0;i<n;i++){
        for(int j = 0;j<m;j++){
            b[i][j] = pos;
            cin>>a[i][j];
            pos++;
        }
    }

    pos = 1;

    for(int i = 0;i<n;i++){
        for(int j = 0;j<m;j++){
            int dx = i,dy = j;
            if(s[i][j] == 'u'){
                dx = i - a[i][j];
            }else if(s[i][j] == 'd'){
                dx = i + a[i][j];
            }else if(s[i][j] == 'l'){
                dy = j - a[i][j];
            }else if(s[i][j] == 'r'){
                dy = j + a[i][j];
            }

            if(check(dx,dy)){
                d.unite(pos,b[dx][dy]);
            }
            pos++;
        }
    }
	
	
	
	if(d.size[d.find(1)] == m*n)puts("YES");
	else puts("NO");

}

int main(){
    int t;cin>>t;
    while(t--)
        slove();

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 6704kb

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: 157ms
memory: 13692kb

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]