QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#283458#3162. Mini Battleshipwarner1129#AC ✓704ms3872kbC++203.1kb2023-12-14 17:29:142023-12-14 17:29:14

Judging History

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

  • [2023-12-14 17:29:14]
  • 评测
  • 测评结果:AC
  • 用时:704ms
  • 内存:3872kb
  • [2023-12-14 17:29:14]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
template <class... T> void dbg(T... x) { char e{}; ((cerr << e << x, e = ' '), ...); }
template <class T> void org(T l, T r) { while (l != r) cerr << ' ' << *l++; cerr << '\n'; }
#define debug(x...) dbg(#x, '=', x, '\n')
#define olist(x...) dbg(#x, '='), org(x)
#else
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define debug(...) ((void)0)
#define olist(...) ((void)0)
#endif
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second

using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using Pt = pair<int, int>;

template <class T> inline constexpr T inf = numeric_limits<T>::max() / 2;
constexpr int mod = 998244353;

template<class T> bool chmin(T &a, T b) { return (b < a and (a = b, true)); }
template<class T> bool chmax(T &a, T b) { return (a < b and (a = b, true)); }
template<class... T> int add(T... x) { int t{}; return (((t += x) %= mod), ...), t; }
template<class... T> int mul(T... x) { i64 t{1}; return (((t *= x) %= mod), ...), t; }
    
void solve() {
    int n, m;
    cin >> n >> m;

    vector G(n, string{});
    for (auto &s : G) {
        cin >> s;
    }

    vector<int> shi(m);
    for (int &x : shi) cin >> x;

    int ans = 0;
    vector vis(n, vector<int>(n));

    function<void(int)> rec = [&](int x) -> void {
        if (x == m) {
            bool ok = true;
            for (int i = 0; i < n and ok; i++)
                for (int j = 0; j < n; j++) {
                    if (G[i][j] == 'O' and !vis[i][j]) {
                        ok = false;
                        break;
                    }
                    if (G[i][j] == 'X' and vis[i][j]) {
                        ok = false;
                        break;
                    }
                }
            if (ok) ans++;
            return;
        } 

        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++) {
                if (j + shi[x] <= n) {
                    bool ok = true;
                    for (int t = 0; t < shi[x]; t++) {
                        if (vis[i][j + t]) ok = false;
                        vis[i][j + t]++;
                    }
                    if (ok) rec(x + 1);
                    for (int t = 0; t < shi[x]; t++) {
                        vis[i][j + t]--;
                    }
                }
                if (shi[x] != 1 and i + shi[x] <= n) {
                    bool ok = true;
                    for (int t = 0; t < shi[x]; t++) {
                        if (vis[i + t][j]) ok = false;
                        vis[i + t][j]++;
                    }
                    if (ok) rec(x + 1);
                    for (int t = 0; t < shi[x]; t++) {
                        vis[i + t][j]--;
                    }
                }
            }
    };
    rec(0);

    cout << ans << '\n';
}

signed main() {
    cin.tie(0)->sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 3
....
.OX.
....
O..X
3
2
1

output:

132

result:

ok single line: '132'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3796kb

input:

4 4
.X.X
.XX.
...X
....
1
2
3
4

output:

6

result:

ok single line: '6'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

2 2
..
..
2
2

output:

4

result:

ok single line: '4'

Test #4:

score: 0
Accepted
time: 5ms
memory: 3868kb

input:

5 5
.....
.....
.....
.....
.....
5
4
3
3
2

output:

80848

result:

ok single line: '80848'

Test #5:

score: 0
Accepted
time: 202ms
memory: 3584kb

input:

5 5
.....
.....
.....
.....
.....
1
1
1
1
1

output:

6375600

result:

ok single line: '6375600'

Test #6:

score: 0
Accepted
time: 704ms
memory: 3644kb

input:

5 5
.....
.....
.....
.....
.....
2
2
2
2
2

output:

18840000

result:

ok single line: '18840000'

Test #7:

score: 0
Accepted
time: 11ms
memory: 3872kb

input:

5 5
.....
XX...
..XXX
XXXX.
....X
5
1
4
2
3

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 7ms
memory: 3576kb

input:

5 5
OOOOO
XXOOO
OOXXX
XXXXO
OOOOX
5
1
4
2
3

output:

1

result:

ok single line: '1'

Test #9:

score: 0
Accepted
time: 11ms
memory: 3524kb

input:

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

output:

1

result:

ok single line: '1'

Test #10:

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

input:

5 5
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
5
1
4
2
3

output:

0

result:

ok single line: '0'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

5 5
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
5
5
5
5
5

output:

240

result:

ok single line: '240'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

1 1
.
1

output:

1

result:

ok single line: '1'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

1 1
O
1

output:

1

result:

ok single line: '1'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

1 1
X
1

output:

0

result:

ok single line: '0'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

4 5
....
....
....
....
4
4
4
4
4

output:

0

result:

ok single line: '0'

Test #16:

score: 0
Accepted
time: 103ms
memory: 3600kb

input:

5 5
OX.XO
XX.XX
.....
XX.XX
OX.XO
1
1
2
1
1

output:

192

result:

ok single line: '192'

Test #17:

score: 0
Accepted
time: 141ms
memory: 3572kb

input:

5 5
OX.XO
XX.XX
.....
XX.XX
OX.XO
1
1
2
2
1

output:

0

result:

ok single line: '0'

Test #18:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

2 2
O.
.X
2
1

output:

2

result:

ok single line: '2'

Test #19:

score: 0
Accepted
time: 1ms
memory: 3572kb

input:

3 5
...
...
...
2
2
1
2
2

output:

432

result:

ok single line: '432'

Test #20:

score: 0
Accepted
time: 12ms
memory: 3524kb

input:

5 4
O...O
.....
..O..
.....
O...O
2
2
2
2

output:

0

result:

ok single line: '0'

Test #21:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

3 2
O.O
.X.
...
3
2

output:

8

result:

ok single line: '8'

Test #22:

score: 0
Accepted
time: 124ms
memory: 3528kb

input:

5 5
X...O
.....
O...X
O.X..
.....
1
1
2
2
5

output:

6856

result:

ok single line: '6856'

Test #23:

score: 0
Accepted
time: 0ms
memory: 3864kb

input:

3 3
.O.
...
OO.
3
2
2

output:

44

result:

ok single line: '44'

Test #24:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

4 3
....
..X.
....
O..X
4
3
1

output:

70

result:

ok single line: '70'

Test #25:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

3 3
O.X
.X.
XO.
1
3
3

output:

0

result:

ok single line: '0'

Test #26:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

2 2
O.
..
1
2

output:

6

result:

ok single line: '6'

Test #27:

score: 0
Accepted
time: 0ms
memory: 3868kb

input:

4 4
.X..
..XX
.O..
X..O
1
3
1
1

output:

714

result:

ok single line: '714'

Test #28:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

2 2
..
OO
1
2

output:

4

result:

ok single line: '4'

Test #29:

score: 0
Accepted
time: 1ms
memory: 3600kb

input:

4 4
....
O...
....
.OO.
3
1
1
2

output:

2390

result:

ok single line: '2390'

Test #30:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

3 3
...
.X.
.XO
2
1
2

output:

36

result:

ok single line: '36'

Test #31:

score: 0
Accepted
time: 51ms
memory: 3596kb

input:

5 5
O.X.O
O...O
XO...
.X.X.
.O...
1
3
1
3
5

output:

48

result:

ok single line: '48'

Test #32:

score: 0
Accepted
time: 14ms
memory: 3640kb

input:

5 5
OO.X.
....X
X....
.....
.....
2
2
5
4
2

output:

3204

result:

ok single line: '3204'

Test #33:

score: 0
Accepted
time: 18ms
memory: 3468kb

input:

5 5
..OX.
..X..
.....
O....
OXX..
5
1
1
2
5

output:

556

result:

ok single line: '556'

Test #34:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

5 2
.....
..X..
.X...
...O.
.....
2
4

output:

112

result:

ok single line: '112'

Test #35:

score: 0
Accepted
time: 0ms
memory: 3540kb

input:

2 2
..
O.
1
1

output:

6

result:

ok single line: '6'

Test #36:

score: 0
Accepted
time: 2ms
memory: 3648kb

input:

5 4
.X.X.
X..O.
...O.
.....
X..X.
1
3
4
2

output:

2722

result:

ok single line: '2722'

Test #37:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

3 3
O..
XO.
.O.
1
1
2

output:

20

result:

ok single line: '20'

Test #38:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

4 3
...O
..O.
....
....
1
1
1

output:

84

result:

ok single line: '84'

Test #39:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

2 2
..
X.
1
2

output:

2

result:

ok single line: '2'

Test #40:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

4 3
X..O
....
O...
.X..
1
4
2

output:

63

result:

ok single line: '63'

Test #41:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

2 2
.O
.X
2
2

output:

0

result:

ok single line: '0'

Test #42:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

4 2
...O
....
....
....
4
2

output:

44

result:

ok single line: '44'

Test #43:

score: 0
Accepted
time: 0ms
memory: 3520kb

input:

4 2
XO..
....
X...
.X..
4
4

output:

0

result:

ok single line: '0'

Test #44:

score: 0
Accepted
time: 1ms
memory: 3836kb

input:

4 4
..O.
....
..X.
.XOO
4
4
1
1

output:

8

result:

ok single line: '8'

Test #45:

score: 0
Accepted
time: 0ms
memory: 3524kb

input:

4 2
....
....
....
..X.
2
2

output:

334

result:

ok single line: '334'