QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#182747 | #6723. Grid with Arrows | ucup-team004 | AC ✓ | 44ms | 8188kb | C++20 | 1.7kb | 2023-09-18 15:01:48 | 2023-09-18 15:01:48 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
void solve() {
int n, m;
std::cin >> n >> m;
std::vector<std::string> s(n);
for (int i = 0; i < n; i++) {
std::cin >> s[i];
}
std::vector a(n, std::vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
std::cin >> a[i][j];
}
}
std::vector<int> f(n * m, -1);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int x = i, y = j;
if (s[i][j] == 'u') {
x -= a[i][j];
} else if (s[i][j] == 'd') {
x += a[i][j];
} else if (s[i][j] == 'l') {
y -= a[i][j];
} else {
y += a[i][j];
}
if (0 <= x && x < n && 0 <= y && y < m) {
f[i * m + j] = x * m + y;
}
}
}
std::vector<int> deg(n * m);
for (int i = 0; i < n * m; i++) {
if (f[i] != -1) {
deg[f[i]]++;
}
}
int x = std::find(deg.begin(), deg.end(), 0) - deg.begin();
if (x == n * m) {
x = 0;
}
std::vector<bool> vis(n * m);
vis[x] = true;
for (int i = 0; i < n * m - 1; i++) {
x = f[x];
if (x == -1 || vis[x]) {
std::cout << "No\n";
return;
}
vis[x] = true;
}
std::cout << "Yes\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
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: 44ms
memory: 8188kb
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