QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#384439 | #6723. Grid with Arrows | Mayuri | WA | 0ms | 3868kb | C++14 | 2.1kb | 2024-04-09 23:51:26 | 2024-04-09 23:51:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define endl '\n'
const ll mod = 1e9 + 7;
ll t;
ll n, m;
int main()//b
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll t; cin >> t;
while (t--) {
cin >> n >> m;
vector<vector<char>>f(n + 1, vector<char>(m + 1));
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= m; j++) {
cin >> f[i][j];
}
}
vector<vector<ll>>a(n + 1, vector<ll>(m + 1));
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, -1));
vector<vector<ll>>scc(n + 1, vector<ll>(m + 1, -1));
vector<ll> sz(n * m + 1);
ll cnt = 0;
function<void(ll, ll)> fdfs = [&](ll x, ll y) -> void {
if (x <= 0 || y <= 0 || x > n || y >m) {
sz[cnt] = 0;
return;
}
if (scc[x][y] != -1)return;
scc[x][y] = cnt;
sz[cnt]++;
ll dx = 0, dy = 0;
if (f[x][y] == 'l')dx = 0, dy = -1;
if (f[x][y] == 'u')dx = -1, dy = 0;
if (f[x][y] == 'r')dx = 0, dy = 1;
if (f[x][y] == 'd')dx = 1, dy = 0;
fdfs(x + dx * a[x][y], y + dy * a[x][y]);
};
function<ll(ll, ll)> dfs = [&](ll x, ll y) -> ll {
if (x < 0 || y < 0 || x > n || y >m)return 0;
ll& ans = dp[x][y];
if (sz[scc[x][y]] != 0) {
return ans = sz[scc[x][y]];
}
if (ans != -1)return ans;
ans = 0;
ll dx = 0, dy = 0;
if (f[x][y] == 'l')dx = 0, dy = -1;
if (f[x][y] == 'u')dx = -1, dy = 0;
if (f[x][y] == 'r')dx = 0, dy = 1;
if (f[x][y] == 'd')dx = 1, dy = 0;
ans = dfs(x + dx * a[x][y], y + dy * a[x][y]) + 1;
//cout << x << " " << y << " " << ans << endl;
return ans;
};
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= m; j++) {
if (scc[i][j] == -1) {
cnt++;
fdfs(i, j);
}
}
}
ll ans = 0;
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= m; j++) {
ans = max(ans, dfs(i, j));
cout << dfs(i, j) << " ";
}cout << endl;
}
if (ans == n * m) {
cout << "yes" << endl;
}
else cout << "no" << endl;
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3868kb
input:
2 2 3 rdd url 2 1 1 1 1 2 2 2 rr rr 1 1 1 1
output:
4 2 4 4 2 4 no 2 1 2 1 no
result:
wrong output format YES or NO expected, but 4 found [1st token]