QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#243113 | #6723. Grid with Arrows | Cipherxzc# | WA | 72ms | 15016kb | C++20 | 2.7kb | 2023-11-07 21:10:19 | 2023-11-07 21:10:19 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int N = 1e5 + 5, dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
int T, n, m, head[N], nxt[N * 2], to[N * 2], tot;
bool vis[N];
vector<vector<int>> a, dir;
vector<vector<bool>> in;
inline void add(int u, int v){
//cout << u << ' ' << v << endl;
to[++tot] = v;
nxt[tot] = head[u];
head[u] = tot;
}
void dfs(int p){
//cout << p << ' ';
vis[p] = true;
tot++;
for (int i = head[p]; i; i = nxt[i]){
int q = to[i];
if (!vis[q]){
dfs(q);
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> T;
while (T--){
cin >> n >> m;
a.resize(n + 1);
dir.resize(n + 1);
in.resize(n + 1);
for (int i = 1; i <= n; i++){
a[i].resize(m + 1);
dir[i].resize(m + 1);
in[i].resize(m + 1);
}
for (int i = 1; i <= n * m; i++){
vis[i] = false;
}
char ch;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
cin >> ch;
if (ch == 'u'){
dir[i][j] = 0;
}else if (ch == 'd'){
dir[i][j] = 1;
}else if (ch == 'l'){
dir[i][j] = 2;
}else{
dir[i][j] = 3;
}
}
}
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
cin >> a[i][j];
}
}
tot = 0;
int cnt = 0;
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
int gg = dir[i][j], x = i + dx[gg] * a[i][j], y = j + dy[gg] * a[i][j];
//cout << x << ' ' << y << endl;
if (1 <= x && x <= n && 1 <= y && y <= m){
if (!in[x][y]){
cnt++;
in[x][y] = true;
}
add((i - 1) * m + j, (x - 1) * m + y);
}
}
}
tot = 0;
if (cnt < n * m - 1){
cout << "No" << endl;
continue;
}else if (cnt < n * m){
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
if (!in[i][j]){
dfs((i - 1) * m + j);
}
}
}
}else{
dfs(1);
}
if (tot == n * m){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3448kb
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
Wrong Answer
time: 72ms
memory: 15016kb
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 No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No No...
result:
wrong answer expected YES, found NO [5th token]