QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#499642 | #6723. Grid with Arrows | zmrzmr | RE | 0ms | 3712kb | C++17 | 1.8kb | 2024-07-31 16:34:43 | 2024-07-31 16:34:45 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<vector<char>> x;
vector<vector<ll>> f;
int main() {
ll t; cin >> t;
for (ll i = 0; i < t; i++) {
ll n, m; scanf("%lld%lld", &n, &m);
vector<vector<char>> x(n, vector<char>(m));
vector<vector<ll>> s(n, vector<ll>(m));
vector<vector<ll>> f(n, vector<ll>(m, -1));
vector<ll> dp(n * m, 0);
ll t = 0, xt = 0, yt = 0;
for (ll i = 0; i < n; i++)for (ll j = 0; j < m; j++)cin >> x[i][j];
for (ll i = 0; i < n; i++)for (ll j = 0; j < m; j++)scanf("%lld", &s[i][j]);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (f[i][j] != -1)
continue;
ll p = i, q = j;
int c = i * n + j;
dp[c] = 1;
t++;
while (p >= 0 && p < n && q >= 0 && q < m) {
f[p][q] = c;
if (x[p][q] == 'u')
p -= s[p][q];
else if (x[p][q] == 'd')
p += s[p][q];
else if (x[p][q] == 'r')
q += s[p][q];
else if (x[p][q] == 'l')
q -= s[p][q];
if (!(p >= 0 && p < n && q >= 0 && q < m))
break;
if (f[p][q]!=-1) {
if (dp[f[p][q]]==1) {
t--;
dp[f[p][q]] = 0;
}
break;
}
}
}
}
if (t <= 1)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
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: -100
Runtime Error
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 Yes No No Yes No