QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#384414#6723. Grid with ArrowsMayuriWA 93ms19420kbC++144.8kb2024-04-09 23:15:182024-04-09 23:15:18

Judging History

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

  • [2024-04-09 23:15:18]
  • 评测
  • 测评结果:WA
  • 用时:93ms
  • 内存:19420kb
  • [2024-04-09 23:15:18]
  • 提交

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<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;
		if (dfs(bx, by) != n * m)flag = false;
		if (flag) {
			cout << "Yes" << endl;
		}
		else cout << "No" << endl;
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3828kb

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: 93ms
memory: 19420kb

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

result:

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