QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#123812#6723. Grid with Arrowsisaunoya#WA 142ms4792kbC++141.4kb2023-07-13 18:03:062023-07-13 18:03:10

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 18:03:10]
  • 评测
  • 测评结果:WA
  • 用时:142ms
  • 内存:4792kb
  • [2023-07-13 18:03:06]
  • 提交

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);
  vector<char> a(n * m);
  for (int i = 0; i < n * m; i += 1) {
    cin >> a[i];
  }

  for (int i = 0; i < n; i += 1) {
    for (int j = 0; j < m; j += 1) {
      int x;
      cin >> x;
      int u = i * m + j;
      int x_v = i, y_v = j;
      char c = a[u];
      if (c == 'l') y_v -= x;
      if (c == 'r') y_v += x;
      if (c == 'u') x_v -= x;
      if (c == 'd') x_v += x;
      
      if (0 <= x_v && x_v < n && 0 <= y_v && y_v < m) {
        int v = x_v * m + y_v;
        e[u] = v;
        deg[v] += 1;
      } else {
        e[u] = -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();
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3440kb

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: 142ms
memory: 4792kb

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
Yes
Yes
Yes
Yes
No
Yes
No
Yes
Yes
No
Yes
No
Yes
No
No
No
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
Yes
No
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
No
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Ye...

result:

wrong answer expected NO, found YES [2nd token]