QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#137665 | #6723. Grid with Arrows | mshcherba# | AC ✓ | 87ms | 16072kb | C++17 | 1.7kb | 2023-08-10 16:13:34 | 2023-08-10 16:13:36 |
Judging History
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;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector<string> s(n);
vector a(n, vector<int>(m)), deg(n, vector<int>(m)), used(n, vector<int>(m));
vector f(n, vector<pair<int, int>>(m, make_pair(-1, -1)));
for (string& si : s) {
cin >> si;
}
for (auto& row : a) {
row.resize(m);
for (int& aij : row) {
cin >> aij;
}
}
FOR(i, 0, n) {
FOR(j, 0, m) {
int ni = i, nj = j;
if (s[i][j] == 'u') {
ni -= a[i][j];
}
else if (s[i][j] == 'd') {
ni += a[i][j];
}
else if (s[i][j] == 'l') {
nj -= a[i][j];
}
else {
nj += a[i][j];
}
if (ni >= 0 && ni < n && nj >= 0 && nj < m) {
f[i][j] = {ni, nj};
deg[ni][nj]++;
}
}
}
int i0 = 0, j0 = 0;
FOR(i, 0, n) {
FOR(j, 0, m) {
if (deg[i][j] == 0) {
i0 = i;
j0 = j;
}
}
}
while (true) {
used[i0][j0] = true;
auto [ni, nj] = f[i0][j0];
if (ni == -1 || used[ni][nj]) {
break;
}
i0 = ni;
j0 = nj;
}
bool ans = true;
FOR(i, 0, n) {
FOR(j, 0, m) {
if (!used[i][j]) {
ans = false;
}
}
}
cout << (ans ? "Yes\n" : "No\n");
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3528kb
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: 87ms
memory: 16072kb
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