QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#123808#6723. Grid with Arrowsisaunoya#WA 1ms3364kbC++141.1kb2023-07-13 17:58:502023-07-13 17:58:51

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-13 17:58:51]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3364kb
  • [2023-07-13 17:58:50]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;


void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> deg(n * m);
  vector<int> e(n * m);
  for (int i = 0; i < n; i += 1) {
    for (int j = 0; j < m; j += 1) {
      char c;
      cin >> c;
      int u = i * m + j, v = u;
      if (c == 'l') --v;
      if (c == 'r') ++v;
      if (c == 'u') v -= m;
      if (c == 'd') v += m;
      e[u] = v;
      if (0 <= v && v < n * m) {
        deg[v] += 1;
      }
    }
  }
  int c = 0;
  for (int i = 0; i < n * m; i += 1) {
    if (deg[i] == 0) {
      c += 1;
    }
  }
  if (c > 1) {
    cout << "No\n";
    return;
  }
  // c = 1 or c = 0
  int s = 0;
  for (int i = 0; i < n * m; i += 1) {
    if (deg[i] == 0) {
      s = i;
    }
  }
  vector<int> q = {s};
  vector<bool> vis(n * m);
  while (q.size() < n * m) {
    int u = q.back();
    if (e[u] == -1) {
      break;
    }
    if (vis[u]) {
      break;
    }
    q.emplace_back(e[u]);
  }
  if (q.size() == n * m) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}

int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3364kb

input:

2
2 3
rdd
url
2 1 1
1 1 2
2 2
rr
rr
1 1
1 1

output:

No
Yes

result:

wrong answer expected YES, found NO [1st token]