QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#261758#7813. 密码锁zlxFTH100 ✓3ms3484kbC++171.3kb2023-11-23 10:14:512023-11-23 10:14:51

Judging History

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

  • [2023-11-23 10:14:51]
  • 评测
  • 测评结果:100
  • 用时:3ms
  • 内存:3484kb
  • [2023-11-23 10:14:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n;
  cin >> n;
  vector<array<int, 5>> a(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 5; j++) {
      cin >> a[i][j];
    }
  }
  array<int, 5> tmp;
  auto check = [&]() {
    for (auto &cur : a) {
      if (tmp == cur) return false;
      bool fl = false;
      for (int i = 0; i < 5; i++) {
        bool ok = true;
        for (int j = 0; j < 5; j++) {
          if (j != i) {
            ok &= tmp[j] == cur[j];
          }
        }
        fl |= ok;
      }
      for (int i = 0; i + 1 < 5; i++) {
        bool ok = true;
        for (int j = 0; j < 5; j++) {
          if (j != i && j != i + 1) {
            ok &= tmp[j] == cur[j];
          } else if (j == i) {
            int v1 = ((tmp[j] - cur[j]) % 10 + 10) % 10;
            int v2 = ((tmp[j + 1] - cur[j + 1]) % 10 + 10) % 10;
            ok &= v1 == v2;
          }
        }
        fl |= ok;
      }
      if (!fl) return false;
    }
    return true;
  };
  int ans = 0;
  auto dfs = [&](auto self, int pos)->void {
    if (pos == 5) {
      ans += check();
      return;
    }
    for (int i = 0; i < 10; i++) {
      tmp[pos] = i;
      self(self, pos + 1);
    }
  };
  dfs(dfs, 0);
  cout << ans << "\n";
  return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 2ms
memory: 3368kb

input:

1
4 9 8 2 5

output:

81

result:

ok single line: '81'

Test #2:

score: 10
Accepted
time: 2ms
memory: 3368kb

input:

1
7 7 5 2 0

output:

81

result:

ok single line: '81'

Test #3:

score: 10
Accepted
time: 3ms
memory: 3484kb

input:

1
8 9 8 7 8

output:

81

result:

ok single line: '81'

Test #4:

score: 10
Accepted
time: 2ms
memory: 3368kb

input:

2
0 3 7 3 8
0 3 6 7 8

output:

6

result:

ok single line: '6'

Test #5:

score: 10
Accepted
time: 2ms
memory: 3412kb

input:

2
7 3 7 9 7
3 3 7 9 3

output:

2

result:

ok single line: '2'

Test #6:

score: 10
Accepted
time: 2ms
memory: 3424kb

input:

4
8 6 9 9 4
8 6 8 9 4
8 6 7 9 4
8 6 1 9 4

output:

6

result:

ok single line: '6'

Test #7:

score: 10
Accepted
time: 2ms
memory: 3400kb

input:

6
0 8 3 9 0
0 4 3 9 0
0 0 3 9 0
0 3 3 9 0
0 5 3 9 0
0 6 3 9 0

output:

4

result:

ok single line: '4'

Test #8:

score: 10
Accepted
time: 2ms
memory: 3372kb

input:

7
2 2 5 6 3
1 8 5 6 3
2 8 7 6 3
2 8 6 6 3
2 8 8 6 3
2 1 5 6 3
2 8 9 6 3

output:

1

result:

ok single line: '1'

Test #9:

score: 10
Accepted
time: 2ms
memory: 3408kb

input:

5
6 6 6 9 5
6 0 0 9 5
6 1 1 9 5
6 2 2 9 5
6 4 4 9 5

output:

5

result:

ok single line: '5'

Test #10:

score: 10
Accepted
time: 2ms
memory: 3388kb

input:

8
9 0 8 6 0
9 5 2 6 0
9 0 7 0 4
9 0 9 6 0
3 0 7 6 0
9 0 7 6 7
4 0 7 6 0
9 8 7 6 0

output:

1

result:

ok single line: '1'