QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#593697#7733. Cool, It’s Yesterday Four Times MoreKdlyhTL 68ms3720kbC++201.9kb2024-09-27 15:32:082024-09-27 15:32:10

Judging History

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

  • [2024-09-27 15:32:10]
  • 评测
  • 测评结果:TL
  • 用时:68ms
  • 内存:3720kb
  • [2024-09-27 15:32:08]
  • 提交

answer

#include<bits/stdc++.h>

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define debug(...) 42
#endif

using i64 = long long;
using STATE = std::array<int, 4>;

namespace ranges = std::ranges;

struct hash {
    size_t operator()(const STATE &p) const {
        return std::hash<int>()(p[0]) ^ std::hash<int>()(p[1]) ^ std::hash<int>()(p[2]) ^ std::hash<int>()(p[3]);
    }
};

void solve()
{
#define tests
    int n, m; std::cin >> n >> m;

    std::vector<std::string> a(n); for (auto& ai : a) {std::cin >> ai;}

    std::vector<std::pair<int, int>> pos;//袋鼠的位置

    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) if (a[i][j] == '.') {pos.emplace_back(i, j);}

    int ans{}; for (auto&[x1, y1] : pos) {
         
        auto valid = [&](int& x, int& y) {return x >= 0 and x < n and y >= 0 and y < m;};

        std::unordered_map<STATE, int, hash> f; auto dfs = [&](auto self, int i1, int j1, int i2, int j2) -> bool {
            STATE now{i1, j1, i2, j2};
            if (f.contains(now)) {return f[now];}
            if (not valid(i2, j2) or a[i2][j2] == 'O') {return f[now] = 1;}
            f[now] = 0;
            for (auto&[di, dj] : {std::make_pair(0, 1), {0, -1}, {1, 0}, {-1, 0}}) {
                int ti{i1 + di}, tj{j1 + dj}; if (valid(ti, tj) and a[ti][tj] != 'O') {
                    f[now] |= self(self, ti, tj, i2 + di, j2 + dj);
                }
            }
            return f[now];
        };

        for (auto&[x2, y2] : pos) if (x1 != x2 or y1 != y2) {dfs(dfs, x1, y1, x2, y2);}

        bool fail{}; for (auto&[x2, y2] : pos) if ((x1 != x2 or y1 != y2) and f[{x1, y1, x2, y2}] != 1) {fail = true; break ;}
        if (not fail) {ans += 1;}
    }

    std::cout << ans << '\n';

}

signed main()
{
    std::cin.tie(nullptr)->sync_with_stdio(false);
    int _(1);
#ifdef tests
    std::cin >> _;
#endif
    while(_--) solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3660kb

input:

4
2 5
.OO..
O..O.
1 3
O.O
1 3
.O.
2 3
OOO
OOO

output:

3
1
0
0

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 3ms
memory: 3612kb

input:

200
2 4
OOO.
OO..
2 3
OOO
.O.
3 3
O.O
OOO
OO.
4 1
.
.
O
O
1 2
.O
1 1
.
2 5
.OO..
.O.O.
2 1
O
O
1 1
O
1 3
.OO
5 1
O
O
.
O
.
5 2
O.
..
O.
.O
..
5 3
...
...
.OO
..O
OOO
3 5
..O.O
.O.O.
.OO.O
5 2
.O
OO
O.
O.
..
2 1
O
O
3 5
.O.OO
O...O
..OO.
1 5
.....
5 1
O
.
O
.
.
5 3
OOO
OO.
.OO
OO.
O.O
2 1
O
.
5 2
O.
...

output:

3
0
0
2
1
1
3
0
0
1
0
7
9
4
4
0
6
5
2
0
1
6
4
5
2
0
0
5
3
3
1
4
1
0
7
5
2
3
7
3
0
6
2
2
2
0
4
6
6
3
3
2
3
5
2
1
0
3
3
4
4
2
2
0
7
6
4
8
5
3
2
5
2
1
2
1
4
0
0
2
5
1
4
6
6
1
6
2
2
3
4
5
2
1
0
1
9
3
4
11
0
3
2
1
0
0
4
3
1
4
3
8
3
0
3
6
2
5
1
3
3
4
0
2
11
2
2
4
0
4
4
6
2
1
2
3
0
5
0
16
4
3
2
6
0
8
3
3
1...

result:

ok 200 lines

Test #3:

score: 0
Accepted
time: 68ms
memory: 3720kb

input:

50
10 9
OOOO.O...
O...O.OOO
.....O...
..OO..O.O
...O..O.O
..OOO..O.
..OOO...O
.OO.O..OO
.O.O.OO..
.O..O.O.O
10 10
.O.OOO.OO.
...OOOOOOO
...O.O..O.
.O.O..O...
.O.O.OO..O
..OO.O..OO
O....O..OO
OO...OOOOO
OO.OO.O..O
.O.O.OOOOO
10 8
O..OOO.O
O.OOOO..
O..OO.OO
OO..OO..
.OOO..O.
.OO.OO.O
OOO..OO.
..O..OO....

output:

31
40
13
25
40
37
27
29
20
26
25
29
21
29
21
31
32
31
33
34
25
31
18
25
41
28
20
45
20
29
18
21
27
28
35
13
20
17
32
29
28
23
23
23
24
18
28
17
35
24

result:

ok 50 lines

Test #4:

score: -100
Time Limit Exceeded

input:

5
1 1000
....O..OO..O..O..OO...OOO.OOOO.O...O....OOOOO.....OO..OOOO.O..O....OOOO..OO..OOOO......O.O.O..O..OO.OO.OO.O....O.O.O.O.O.OO..O.O.OO..O..OO..O.OOO...O...O.O.O..O....O.OO...O..O...O.OOO..OO.O..O.OO.O.O..OOOO..O.OO.O.O....O.OO.......OOOO....O.O.O.O..OOO.O.OO.OOO..O...O.O.O.O.OO.O.OOOO...O.OO.....

output:


result: