QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#243213#6723. Grid with Arrowsgzzz#WA 59ms10468kbC++201.6kb2023-11-07 22:08:542023-11-07 22:08:55

Judging History

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

  • [2023-11-07 22:08:55]
  • 评测
  • 测评结果:WA
  • 用时:59ms
  • 内存:10468kb
  • [2023-11-07 22:08:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e5+10;
string mp[maxn];
vector<vector<int> > s;
int in[maxn],out[maxn],fa[maxn];
int find(int x){
	if(fa[x]==x) {
		return x;
	}
	return fa[x]=find(fa[x]);
}
void unit(int x,int y){
	fa[find(x)]=find(y);
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;cin>>t;
	while(t--) {
		int n,m;
		cin>>n>>m;
		for(int i=0;i<n*m;i++){
			fa[i]=i;
		}
		s.clear();
		for(int i=0;i<n;i++){
			mp[i].clear();
			cin>>mp[i];
		}
		for(int i=1;i<=n;i++){
			vector<int> tmp;
			for(int j=1;j<=m;j++){
				int x;cin>>x;
				tmp.push_back(x);
			}
			s.push_back(tmp);
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				int fr=i*m+j;
				int tox=i,toy=j;
				if(mp[i][j]=='r') {
					toy+=s[i][j];
				}
				else if(mp[i][j]=='l'){
					toy-=s[i][j];
				}
				else if(mp[i][j]=='u'){
					tox-=s[i][j];
				}
				else {
					tox+=s[i][j];
				}
				if(tox<0||tox>=n||toy<0||toy>=m) {
					continue;
				}
				else {
					int to=tox*m+toy;
					in[to]++;
					out[fr]++;
					unit(fr,to);
				}
			}
		}
		int num1=0,num2=0; 	
		for(int i=0;i<=(n-1)*m+(m-1);i++){
			if(in[i]>out[i]) {
				num1++;
			}
			else if(out[i]>in[i]){
				num2++;
			}
		}
		if(num1!=num2){
			cout<<"No\n";
		}
		else {
			if(num1==1||num1==0) {
				bool flag=true;
				for(int i=1;i<n*m&&flag;i++){
					if(find(i)!=find(0)) {
						flag=false;
					}
				}
				if(flag) cout<<"Yes\n";
				else cout<<"No\n";
			}
			else {
				cout<<"No\n";
			}
		}
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 6748kb

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: 59ms
memory: 10468kb

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

result:

wrong answer expected YES, found NO [5th token]