QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#499694 | #6723. Grid with Arrows | Umok | AC ✓ | 157ms | 20932kb | C++20 | 2.2kb | 2024-07-31 17:09:46 | 2024-07-31 17:09:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
const int N = 1e5 + 5;
#define int long long
typedef pair<int, int> PII;
#define MAX LONG_LONG_MAX
string mp[N];
vector<int> ar[N];
int f[N];
vector<int> st[N];
int n, m, d[N];
int finds(int x)
{
return f[x] == x ? f[x] : f[x] = finds(f[x]);
}
PII find(int x, int y)
{
int xx = x, yy = y;
if (mp[x][y] == 'r')
yy += ar[x][y];
else if (mp[x][y] == 'd')
xx += ar[x][y];
else if (mp[x][y] == 'l')
yy -= ar[x][y];
else
xx -= ar[x][y];
if (xx < 1 || xx > n || yy < 0 || yy > m)
return {0, 0};
return {xx, yy};
}
void solve()
{
cin >> n >> m;
int ans = n * m;
for (int i = 1; i <= n; i++)
{
ar[i].clear();
st[i].clear();
cin >> mp[i];
mp[i] = " " + mp[i];
}
for (int i = 1; i <= n; i++)
{
ar[i].push_back(0);
st[i].push_back(0);
for (int j = 1; j <= m; j++)
{
int x;
cin >> x;
ar[i].push_back(x);
st[i].push_back(0);
}
}
st[0].push_back(0);
for (int i = 1; i <= ans; i++)
f[i] = i, d[i] = 0;
int num = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
st[i][j] = num++;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
{
int a = st[i][j];
auto q = find(i, j);
if (q.first < 1 || q.second < 1)
continue;
int b = st[q.first][q.second];
f[finds(a)] = finds(b);
d[b]++;
}
int x = finds(1);
for (int i = 2; i <= ans; i++)
{
if (finds(i) != x)
{
puts("No");
return;
}
}
int res = 0;
for (int i = 1; i <= ans; i++)
{
if (!d[i])
res++;
if (res > 1)
{
cout << "No" << endl;
return;
}
}
cout << "Yes" << endl;
}
signed main()
{
int tcase;
cin >> tcase;
while (tcase--)
solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 10276kb
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: 157ms
memory: 20932kb
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