QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#137642#6723. Grid with ArrowsYarema#AC ✓57ms8408kbC++171.5kb2023-08-10 15:18:502023-08-10 15:18:51

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-10 15:18:51]
  • 评测
  • 测评结果:AC
  • 用时:57ms
  • 内存:8408kb
  • [2023-08-10 15:18:50]
  • 提交

answer

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

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int N = 200500;
int g[N];
map<char, PII> mapka;
int deg[N];
bool used[N];

int dfs(int v)
{
	int cnt = 1;
	used[v] = 1;
	if (g[v] != -1 && !used[g[v]]) cnt += dfs(g[v]);
	return cnt;
}

void solve()
{
	int n, m;
	cin >> n >> m;
	
	
	FOR (i, 0, n * m)
	{
		used[i] = 0;
		deg[i] = 0;
		g[i] = -1;
	}
	
	vector<string> v(n);
	FOR (i, 0, n) cin >> v[i];
	vector<VI> a(n, VI(m));
	FOR (i, 0, n) FOR (j, 0, m) cin >> a[i][j];
	
	FOR (i, 0, n)
	{
		FOR (j, 0, m)
		{
			int x = i * m + j;
			int ii = i + mapka[v[i][j]].F * a[i][j];
			int jj = j + mapka[v[i][j]].S * a[i][j];
			if (ii >= 0 && ii < n && jj >= 0 && jj < m)
			{
				int y = ii * m + jj;
				g[x] = y;
				deg[y]++;
			}
		}
	}
	int st = 0;
	FOR (i, 0, n * m)
	{
		if (deg[st] > deg[i]) st = i;
	}
	int c = dfs(st);
	if (c == n * m)
		cout << "Yes\n";
	else
		cout << "No\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	
	mapka['u'] = {-1, 0};
	mapka['r'] = {0, 1};
	mapka['d'] = {1, 0};
	mapka['l'] = {0, -1};
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	
	return 0;
}

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

詳細信息

Test #1:

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

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: 57ms
memory: 8408kb

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