QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#214223#6723. Grid with Arrowsyyyyy3RE 2ms6660kbC++141.6kb2023-10-14 18:01:522023-10-14 18:01:54

Judging History

This is the latest submission verdict.

  • [2023-10-14 18:01:54]
  • Judged
  • Verdict: RE
  • Time: 2ms
  • Memory: 6660kb
  • [2023-10-14 18:01:52]
  • Submitted

answer


#include<bits/stdc++.h>
#define endl '\n'
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define _ int _T; cin >> _T; while(_T --) 
#define int long long

using namespace std;
const int N = 1e5 + 10;
const int MAX = 1e3 + 10;
int n,m;
string s[N];
int g[N];
int r[N];
bool st[N];

void bfs(){
	queue<int> q;
	for(int i = 1;i <= n * m;i ++){
		if(!r[i]){
			q.push(i);
			break;
		}
	} if(!q.size()) q.push(1);
	int ans = 0;
	while(q.size()){
		int t = q.front();
		q.pop();
		if(st[t]) continue;
		st[t] = true;
	//	cout << t << "TTT" << endl;
		ans ++;
		q.push(g[t]);
	}// cout << ans << endl;
	if(ans == n * m) cout << "YES" << endl;
	else cout << "NO" << endl;
}

void solve(){
	int pos = 1;
	cin >> n >> m;
	for(int i = 1;i <= n * m;i ++){
		st[i] = false;
		g[i] = i;
		r[i] = 0;
	}
	for(int i = 1;i <= n;i ++){
		cin >> s[i];
	}

	for(int i = 1;i <= n;i ++){
		for(int j = 0;j < m;j ++){
			int a; cin >> a;
			if(s[i][j] == 'r' && j + 1 + a <= m){
				g[pos] = pos + a;
				r[pos + a] ++;
			}
			if(s[i][j] == 'l' && j + 1 - a >= 1){
				g[pos] = pos - a;
				r[pos - a] ++;
			}
			if(s[i][j] == 'u' && i - a >= 1){
				g[pos] = pos - a*m;
				r[pos - a * m] ++;
			}
			if(s[i][j] == 'd'){
				g[pos] = pos + a * m;
				r[pos + a * m] ++;
			}
			pos ++;
		}
	} 
	bfs();
//	for(int i = 1;i <= n * m;i ++){
//		for(auto t : g[i]){
//			cout << t << " " << r[t] << " " << i << " " << t ;
//		} cout << endl;
//	}
}

signed main(){
//	fast();
	_
	solve();
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Runtime Error

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
NO
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
YE...

result: