QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#692741#6723. Grid with ArrowsShuishui#AC ✓62ms11880kbC++142.0kb2024-10-31 14:58:382024-10-31 14:58:39

Judging History

This is the latest submission verdict.

  • [2024-10-31 14:58:39]
  • Judged
  • Verdict: AC
  • Time: 62ms
  • Memory: 11880kb
  • [2024-10-31 14:58:38]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define Sz(x) (int)(x).size()
#define bit(x) (1ll << (x))
using ll = long long;
using db = double;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vd = vector<db>;
mt19937 mrand(time(0));

void solve(void)
{
	int n, m;
	cin >> n >> m;
	vs s(n + 2);
	for (int i = 1; i <= n; i++)
	{
		cin >> s[i];
		s[i] = ' ' + s[i];
	}

	vii a(n + 2, vi(m + 2));
	vii id(n + 2, vi(m + 2));
	vi nxt(n * m + 2), vis(n * m + 2), d(n * m + 2);
	int tot = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			id[i][j] = ++tot;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
		{
			int x;
			cin >> x;
			int nx = i, ny = j;
			if (s[i][j] == 'u') nx -= x;
			else if (s[i][j] == 'd') nx += x;
			else if (s[i][j] == 'l') ny -= x;
			else ny += x;

			if (1 <= nx && nx <= n && 1 <= ny && ny <= m)
			{
				nxt[id[i][j]] = id[nx][ny];
				d[id[nx][ny]]++;
			}
		}

	int f1 = 1;
	for (int i = 1; i <= n * m; i++)
		if (d[i] != 1)
		{
			f1 = 0;
			if (d[i] == 0)
			{
				int u = i;
				// cerr << u << "\n";
				int cnt = 0;
				while (u && !vis[u])
				{
					// cerr << u 
					vis[u] = 1;
					cnt++;
					u = nxt[u];
				}
				if (cnt == n * m)
				{
					cout << "Yes\n";
					return;
				}
			}
		}
	
	if (f1)
	{
		int u = 1;
		int cnt = 0;
		while (u && !vis[u])
		{
			// cerr << u 
			vis[u] = 1;
			cnt++;
			u = nxt[u];
		}
		if (cnt == n * m)
		{
			cout << "Yes\n";
			return;
		}
		cout << "No\n";
		return;
	}

	cout << "No\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	// cout << fixed << setprecision(10);

	int T = 1;
	cin >> T;
	for (int i = 1; i <= T; i++)
	solve();

	return 0;
}

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

詳細信息

Test #1:

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

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: 62ms
memory: 11880kb

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