QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#384425#6723. Grid with ArrowsMayuriWA 0ms3608kbC++145.4kb2024-04-09 23:23:442024-04-09 23:23:45

Judging History

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

  • [2024-04-09 23:23:45]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3608kb
  • [2024-04-09 23:23:44]
  • 提交

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;
	}
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3608kb

input:

2
2 3
rdd
url
2 1 1
1 1 2
2 2
rr
rr
1 1
1 1

output:

1 1 1 
1 1 1 
Yes
0 0 
1 1 
No

result:

wrong output format YES or NO expected, but 1 found [1st token]