QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#137712 | #6723. Grid with Arrows | PetroTarnavskyi# | AC ✓ | 46ms | 9860kb | C++17 | 1.4kb | 2023-08-10 16:57:51 | 2023-08-10 16:57:52 |
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;
const int N = 1 << 17;
int g[N];
int cnt[N];
int u[N];
void clear(int n){
FOR(i, 0, n){
g[i] = -1;
cnt[i] = 0;
u[i] = 0;
}
}
int n, m;
int id(int i, int j){
return i * m + j;
}
int a[N];
string grid[N];
void solve(){
cin >> n >> m;
FOR(i, 0, n)
cin >> grid[i];
FOR(i, 0, n * m)
cin >> a[i];
FOR(i, 0, n){
FOR(j, 0, m){
int v = id(i, j);
int ni = i + (grid[i][j] == 'd') * a[v] - (grid[i][j] == 'u') * a[v];
int nj = j + (grid[i][j] == 'r') * a[v] - (grid[i][j] == 'l') * a[v];
if(0 <= ni && ni < n && 0 <= nj && nj < m){
int to = id(ni, nj);
g[v] = to;
cnt[to]++;
}
}
}
int v = 0;
FOR(i, 0, n * m)
if(cnt[i] == 0)
v = i;
int sz = 0;
while(v != -1 && !u[v]){
u[v] = 1;
sz++;
v = g[v];
}
if(sz == n * m)
cout << "Yes\n";
else
cout << "No\n";
clear(n * m);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while(t--)
solve();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 7904kb
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: 46ms
memory: 9860kb
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