QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#384427#6723. Grid with ArrowsMayuriAC ✓81ms20004kbC++145.4kb2024-04-09 23:24:382024-04-09 23:24:39

Judging History

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

  • [2024-04-09 23:24:39]
  • 评测
  • 测评结果:AC
  • 用时:81ms
  • 内存:20004kb
  • [2024-04-09 23:24:38]
  • 提交

answer

//#define _CRT_SECURE_NO_WARNINGS
////#include<bits/stdc++.h>
////using namespace std;
////typedef long long ll;
////typedef long double ld;
////#define endl '\n'
////const ll mod = 1e9 + 7;
////ll T;
////ll l, r;
////ll f(ll x) {
////	ll ans = 1;
////	while (x) {
////		ans = ans * (x % 10) % mod;
////		x /= 10;
////	}
////	return ans;
////}
////int main()
////{
////	ios::sync_with_stdio(0);
////	cin.tie(0);
////	cout.tie(0);
////	ll T; cin >> T;
////	while (T--) {
////		cin >> l >> r;
////		if (l / 10 != r / 10) {
////			cout << 0 << endl;
////			continue;
////		}
////		ll ans = 1;
////		for (ll i = l; i <= r; i++)ans = (ans * f(i)) % mod;
////		cout << ans << endl;
////	}
////}
//#include<bits/stdc++.h>
//using namespace std;
//typedef long long ll;
//typedef long double ld;
//#define endl '\n'
//const ll mod = 1e9 + 7;
//ll T;
//ll n, m;
//
//int main()
//{
//	ios::sync_with_stdio(0);
//	cin.tie(0);
//	cout.tie(0);
//	ll T; cin >> T;
//	while (T--) {
//		cin >> n >> m;
//		vector<vector<char>>f(n + 1, vector<char>(m + 1));
//		for (ll i = 1; i <= n; i++) {
//			for (ll j = 1; j <= m; j++) {
//				cin >> f[i][j];
//			}
//		}
//		vector<vector<ll>>a(n + 1, vector<ll>(m + 1));
//		for (ll i = 1; i <= n; i++) {
//			for (ll j = 1; j <= m; j++) {
//				cin >> a[i][j];
//			}
//		}
//		vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, -1));
//		vector<vector<ll>>scc(n + 1, vector<ll>(m + 1, -1));
//		vector<ll> sz(n * m + 1);
//		ll cnt = 0;
//		function<void(ll, ll)> fdfs = [&](ll x, ll y) -> void {
//			if (x < 0 || y < 0 || x > n || y >m) {
//				sz[cnt] = 0;
//				return;
//			}
//			if (scc[x][y] != -1)return;
//			scc[x][y] = cnt;
//			sz[cnt]++;
//			ll dx = 0, dy = 0;
//			if (f[x][y] == 'l')dx = 0, dy = -1;
//			if (f[x][y] == 'u')dx = -1, dy = 0;
//			if (f[x][y] == 'r')dx = 0, dy = 1;
//			if (f[x][y] == 'd')dx = 1, dy = 0;
//			fdfs(x + dx * a[x][y], y + dy * a[x][y]);
//			};
//		function<ll(ll, ll)> dfs = [&](ll x, ll y) -> ll {
//			if (x < 0 || y < 0 || x > n || y >m)return 0;
//			ll& ans = dp[x][y];
//			if (sz[scc[x][y]] != 0) {
//				return ans = sz[scc[x][y]];
//			}
//			if (ans != -1)return ans;
//			ans = 0;
//			ll dx = 0, dy = 0;
//			if (f[x][y] == 'l')dx = 0, dy = -1;
//			if (f[x][y] == 'u')dx = -1, dy = 0;
//			if (f[x][y] == 'r')dx = 0, dy = 1;
//			if (f[x][y] == 'd')dx = 1, dy = 0;
//			ans = dfs(x + dx * a[x][y], y + dy * a[x][y]) + 1;
//			cout << x << " " << y << " " << ans << endl;
//			return ans;
//		};
//		for (ll i = 1; i <= n; i++) {
//			for (ll j = 1; j <= m; j++) {
//				if (scc[i][j] == -1) {
//					cnt++;
//					fdfs(i, j);
//				}
//			}
//		}
//		ll ans = 0;
//		for (ll i = 1; i <= n; i++) {
//			for (ll j = 1; j <= m; j++) {
//				ans = max(ans, dfs(i, j));
//				cout << dfs(i, j) << " ";
//			}cout << endl;
//		}
//		if (ans == n * m) {
//			cout << "Yes" << endl;
//		}
//		else cout << "No" << endl;
//	}
//}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define endl '\n'
const ll mod = 1e9 + 7;
ll T;
ll n, m;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll T; cin >> T;
	while (T--) {
		cin >> n >> m;
		vector<vector<char>>f(n + 1, vector<char>(m + 1));
		for (ll i = 1; i <= n; i++) {
			for (ll j = 1; j <= m; j++) {
				cin >> f[i][j];
			}
		}
		vector<vector<ll>>a(n + 1, vector<ll>(m + 1));
		for (ll i = 1; i <= n; i++) {
			for (ll j = 1; j <= m; j++) {
				cin >> a[i][j];
			}
		}
		vector<vector<ll>>c(n + 1, vector<ll>(m + 1));
		for (ll x = 1; x <= n; x++) {
			for (ll y = 1; y <= m; y++) {
				ll dx = 0, dy = 0;
				if (f[x][y] == 'l')dx = 0, dy = -1;
				if (f[x][y] == 'u')dx = -1, dy = 0;
				if (f[x][y] == 'r')dx = 0, dy = 1;
				if (f[x][y] == 'd')dx = 1, dy = 0;
				ll tx = x + dx * a[x][y], ty = y + dy * a[x][y];
				if (tx < 0 || ty < 0 || tx > n || ty >m)continue;
				c[tx][ty]++;
			}
		}
		ll bx = 1, by = 1;
		for (ll x = 1; x <= n; x++) {
			for (ll y = 1; y <= m; y++) {
				if (c[x][y] == 0) {
					bx = x;
					by = y;
				}
			}
		}
		vector<vector<bool>> dp(n + 1, vector<bool>(m + 1));
		function<void(ll, ll)> dfs = [&](ll x, ll y) -> void {
			if (x < 0 || y < 0 || x > n || y >m)return;
			if (dp[x][y])return;
			dp[x][y] = true;
			ll dx = 0, dy = 0;
			if (f[x][y] == 'l')dx = 0, dy = -1;
			if (f[x][y] == 'u')dx = -1, dy = 0;
			if (f[x][y] == 'r')dx = 0, dy = 1;
			if (f[x][y] == 'd')dx = 1, dy = 0;
			dfs(x + dx * a[x][y], y + dy * a[x][y]);
		};
		//vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, -1));
		//function<ll(ll, ll)> dfs = [&](ll x, ll y) -> ll {
		//	if (x < 0 || y < 0 || x > n || y >m)return 0;
		//	ll& ans = dp[x][y];
		//	if (ans != -1)return ans;
		//	ans = 0;
		//	ll dx = 0, dy = 0;
		//	if (f[x][y] == 'l')dx = 0, dy = -1;
		//	if (f[x][y] == 'u')dx = -1, dy = 0;
		//	if (f[x][y] == 'r')dx = 0, dy = 1;
		//	if (f[x][y] == 'd')dx = 1, dy = 0;
		//	ans = dfs(x + dx * a[x][y], y + dy * a[x][y]) + 1;
		//	//cout << x << " " << y << " " << ans << endl;
		//	return ans;
		//	};
		bool flag = true;
		dfs(bx, by);
		for (ll i = 1; i <= n; i++) {
			for (ll j = 1; j <= m; j++) {
				//cout << dp[i][j] << " ";
				if (!dp[i][j])flag = false;
			}//cout << endl;
		}
		if (flag) {
			cout << "Yes" << endl;
		}
		else cout << "No" << endl;
	}
}

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

详细

Test #1:

score: 100
Accepted
time: 1ms
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: 0
Accepted
time: 81ms
memory: 20004kb

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