QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#692692#6723. Grid with ArrowsShuishui#WA 70ms11864kbC++141.8kb2024-10-31 14:54:592024-10-31 14:55:00

Judging History

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

  • [2024-10-31 14:55:00]
  • 评测
  • 测评结果:WA
  • 用时:70ms
  • 内存:11864kb
  • [2024-10-31 14:54:59]
  • 提交

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)
	{
		cout << "Yes\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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 70ms
memory: 11864kb

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
Yes
No
Yes
Yes
No
Yes
No
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
Yes
No
Yes
Yes
Yes
No
No
Yes
Yes
Yes
No
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
No
No
Yes
Yes
No
No
Yes
Yes
Yes
No
Yes
Yes...

result:

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