QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#123808 | #6723. Grid with Arrows | isaunoya# | WA | 1ms | 3364kb | C++14 | 1.1kb | 2023-07-13 17:58:50 | 2023-07-13 17:58:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m;
cin >> n >> m;
vector<int> deg(n * m);
vector<int> e(n * m);
for (int i = 0; i < n; i += 1) {
for (int j = 0; j < m; j += 1) {
char c;
cin >> c;
int u = i * m + j, v = u;
if (c == 'l') --v;
if (c == 'r') ++v;
if (c == 'u') v -= m;
if (c == 'd') v += m;
e[u] = v;
if (0 <= v && v < n * m) {
deg[v] += 1;
}
}
}
int c = 0;
for (int i = 0; i < n * m; i += 1) {
if (deg[i] == 0) {
c += 1;
}
}
if (c > 1) {
cout << "No\n";
return;
}
// c = 1 or c = 0
int s = 0;
for (int i = 0; i < n * m; i += 1) {
if (deg[i] == 0) {
s = i;
}
}
vector<int> q = {s};
vector<bool> vis(n * m);
while (q.size() < n * m) {
int u = q.back();
if (e[u] == -1) {
break;
}
if (vis[u]) {
break;
}
q.emplace_back(e[u]);
}
if (q.size() == n * m) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
int main() {
int t;
cin >> t;
while (t--) {
solve();
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3364kb
input:
2 2 3 rdd url 2 1 1 1 1 2 2 2 rr rr 1 1 1 1
output:
No Yes
result:
wrong answer expected YES, found NO [1st token]