QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#413260 | #3162. Mini Battleship | ivan_len | AC ✓ | 1273ms | 3764kb | C++20 | 3.1kb | 2024-05-17 10:42:02 | 2024-05-17 10:42:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
#define PB push_back
#define MP make_pair
#define A first
#define B second
#define SZ(x) int(x.size())
#define FR(i, a, b) for (int i = (a); i < (b); ++i)
#define FOR(i, n) FR(i, 0, n)
const int M = 1000000007;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
int n, m;
vector<vi> a;
vi b;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
a.resize(n, vi(n, -1));
b.resize(m);
int yes = 0, no = 0;
FOR(i, n) {
string s;
cin >> s;
FOR(j, n) {
if (s[j] == 'X') {
a[i][j] = 0;
no |= 1 << (i * n + j);
}
if (s[j] == 'O') {
a[i][j] = 1;
yes |= 1 << (i * n + j);
}
}
}
vi buc(6);
FOR(i, m) {
cin >> b[i];
buc[b[i]]++;
}
int tot = 0;
FOR(i, m) tot += b[i];
int mx = 0, idx = 0;
FOR(i, 6) {
if (buc[i] > mx) {
mx = buc[i];
idx = i;
}
}
FOR(i, m) {
if (b[i] == idx) b[i] = -1;
}
mx = m - mx;
sort(b.rbegin(), b.rend());
FOR(i, m) {
if (b[i] == -1) b[i] = idx;
}
int ans = 0;
FOR(i, (1 << (n * n))) {
if ((i & yes) != yes) continue;
if (((~i) & no) != no) continue;
int cnt = 0;
FOR(j, n * n) {
cnt += ((i >> j) & 1);
}
if (cnt != tot) continue;
vector<vi> t(n, vi(n));
FOR(j, n) {
FOR(k, n) {
if ((i >> (j * n + k)) & 1) t[j][k] = 1;
}
}
function<int(int, int)> get = [&](int x, int num) {
if (num == m) return 1;
int nxt_len = b[num];
int acc = 0;
bool fin = false;
FOR(i, n) {
if (fin) break;
FOR(j, n) {
if ((x >> (i * n + j)) & 1) {
if (num >= mx) fin = true;
int mask = 0;
if (j <= n - nxt_len) {
FOR(k, nxt_len) mask |= (1 << (i * n + j + k));
if ((x & mask) == mask) {
acc += get(x ^ mask, num + 1);
}
}
mask = 0;
if (nxt_len > 1) {
FOR(k, nxt_len) mask |= (1 << (i * n + j + k * n));
if ((x & mask) == mask) {
acc += get(x ^ mask, num + 1);
}
}
}
if (fin) break;
}
}
return acc;
};
ans += get(i, 0);
}
FR(i, 1, m - mx + 1) ans *= i;
cout << ans << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3512kb
input:
4 3 .... .OX. .... O..X 3 2 1
output:
132
result:
ok single line: '132'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3468kb
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: 3524kb
input:
2 2 .. .. 2 2
output:
4
result:
ok single line: '4'
Test #4:
score: 0
Accepted
time: 1272ms
memory: 3520kb
input:
5 5 ..... ..... ..... ..... ..... 5 4 3 3 2
output:
80848
result:
ok single line: '80848'
Test #5:
score: 0
Accepted
time: 541ms
memory: 3756kb
input:
5 5 ..... ..... ..... ..... ..... 1 1 1 1 1
output:
6375600
result:
ok single line: '6375600'
Test #6:
score: 0
Accepted
time: 1273ms
memory: 3452kb
input:
5 5 ..... ..... ..... ..... ..... 2 2 2 2 2
output:
18840000
result:
ok single line: '18840000'
Test #7:
score: 0
Accepted
time: 23ms
memory: 3756kb
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: 25ms
memory: 3560kb
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: 25ms
memory: 3760kb
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: 25ms
memory: 3524kb
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: 25ms
memory: 3568kb
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: 1ms
memory: 3756kb
input:
1 1 . 1
output:
1
result:
ok single line: '1'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
1 1 O 1
output:
1
result:
ok single line: '1'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
1 1 X 1
output:
0
result:
ok single line: '0'
Test #15:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
4 5 .... .... .... .... 4 4 4 4 4
output:
0
result:
ok single line: '0'
Test #16:
score: 0
Accepted
time: 27ms
memory: 3480kb
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: 26ms
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: 3764kb
input:
2 2 O. .X 2 1
output:
2
result:
ok single line: '2'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3524kb
input:
3 5 ... ... ... 2 2 1 2 2
output:
432
result:
ok single line: '432'
Test #20:
score: 0
Accepted
time: 40ms
memory: 3444kb
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: 3568kb
input:
3 2 O.O .X. ... 3 2
output:
8
result:
ok single line: '8'
Test #22:
score: 0
Accepted
time: 57ms
memory: 3572kb
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: 1ms
memory: 3456kb
input:
3 3 .O. ... OO. 3 2 2
output:
44
result:
ok single line: '44'
Test #24:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
4 3 .... ..X. .... O..X 4 3 1
output:
70
result:
ok single line: '70'
Test #25:
score: 0
Accepted
time: 0ms
memory: 3520kb
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: 3460kb
input:
2 2 O. .. 1 2
output:
6
result:
ok single line: '6'
Test #27:
score: 0
Accepted
time: 1ms
memory: 3572kb
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: 3568kb
input:
2 2 .. OO 1 2
output:
4
result:
ok single line: '4'
Test #29:
score: 0
Accepted
time: 1ms
memory: 3668kb
input:
4 4 .... O... .... .OO. 3 1 1 2
output:
2390
result:
ok single line: '2390'
Test #30:
score: 0
Accepted
time: 1ms
memory: 3484kb
input:
3 3 ... .X. .XO 2 1 2
output:
36
result:
ok single line: '36'
Test #31:
score: 0
Accepted
time: 28ms
memory: 3760kb
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: 68ms
memory: 3628kb
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: 43ms
memory: 3668kb
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: 90ms
memory: 3452kb
input:
5 2 ..... ..X.. .X... ...O. ..... 2 4
output:
112
result:
ok single line: '112'
Test #35:
score: 0
Accepted
time: 1ms
memory: 3520kb
input:
2 2 .. O. 1 1
output:
6
result:
ok single line: '6'
Test #36:
score: 0
Accepted
time: 45ms
memory: 3760kb
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: 3524kb
input:
3 3 O.. XO. .O. 1 1 2
output:
20
result:
ok single line: '20'
Test #38:
score: 0
Accepted
time: 1ms
memory: 3524kb
input:
4 3 ...O ..O. .... .... 1 1 1
output:
84
result:
ok single line: '84'
Test #39:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
2 2 .. X. 1 2
output:
2
result:
ok single line: '2'
Test #40:
score: 0
Accepted
time: 1ms
memory: 3756kb
input:
4 3 X..O .... O... .X.. 1 4 2
output:
63
result:
ok single line: '63'
Test #41:
score: 0
Accepted
time: 1ms
memory: 3528kb
input:
2 2 .O .X 2 2
output:
0
result:
ok single line: '0'
Test #42:
score: 0
Accepted
time: 1ms
memory: 3472kb
input:
4 2 ...O .... .... .... 4 2
output:
44
result:
ok single line: '44'
Test #43:
score: 0
Accepted
time: 1ms
memory: 3444kb
input:
4 2 XO.. .... X... .X.. 4 4
output:
0
result:
ok single line: '0'
Test #44:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
4 4 ..O. .... ..X. .XOO 4 4 1 1
output:
8
result:
ok single line: '8'
Test #45:
score: 0
Accepted
time: 1ms
memory: 3756kb
input:
4 2 .... .... .... ..X. 2 2
output:
334
result:
ok single line: '334'