QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#505801 | #4642. 炮兵阵地 | RainPPR | 100 ✓ | 148ms | 13408kb | C++23 | 1.2kb | 2024-08-05 11:39:14 | 2024-08-05 11:39:15 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
constexpr int mod = 1e8;
int n, m, mp[101];
vector<int> state;
void init() {
for (int i = 0; i < (1 << m); ++i) {
if (i & (i << 1)) continue;
if (i & (i << 2)) continue;
state.push_back(i);
}
}
unordered_map<int, unordered_map<int, int>> dp[101];
//int dp[101][1024][1024];
#define pop_count(x) __builtin_popcount(x)
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
string str;
cin >> str;
for (int j = 0; j < m; ++j) {
mp[i] |= (str[j] == 'H') << j;
}
}
init();
dp[0][0][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int a : state) {
if (a & mp[i]) continue;
for (int b : state) {
if (a & b) continue;
if (b & mp[i - 1]) continue;
for (int c : state) {
if (a & c) continue;
if (b & c) continue;
dp[i][a][b] = max(dp[i][a][b], dp[i - 1][b][c] + pop_count(a));
}
}
}
}
int ans = 0;
for (int a : state) for (int b : state) ans = max(ans, dp[n][a][b]);
cout << ans << endl;
return 0;
}
詳細信息
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 0ms
memory: 3828kb
input:
5 4 PHPP PPHH PPPP PHPP PHHP
output:
6
result:
ok single line: '6'
Test #2:
score: 10
Accepted
time: 0ms
memory: 3608kb
input:
8 4 HPPH PPPP HPPH PHHP PHHP HPPH PPPP HPPH
output:
8
result:
ok single line: '8'
Test #3:
score: 10
Accepted
time: 39ms
memory: 6324kb
input:
30 10 PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPH PPPPPPPPPP PHPPPPPHPP PPPPPPPPPP PPPPPPPPPP PPPPPPPHPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPHPHPPPHP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP HPHPPHPPPP PPPPPPHPPH HPPPPHPPPP PPPPPPPHHP PPPPHPPPPP PPPPPPPPPP PPPPPPPHPP PPPPPPPPPP PPPPPPPPPP PPPHPPPP...
output:
97
result:
ok single line: '97'
Test #4:
score: 10
Accepted
time: 16ms
memory: 5840kb
input:
50 10 PPHPPHPPPP PPPHPPPHPP PHPPPHPPPH PHPHHHHPPH PPPPPPPPPH PPPHPPHPPP PHPPPPPHPH HPHPPPPPPP PPPHPHPPPP HHHHPPPHHP PPPHPPPHHP PPPHPPPPHP PPHHHPHPHP PPHPHPPPHP HHPPPPPPPP HPPPPPHPPH PPHPPPHPHH HHHPHHPHPP PPPHHPHPPH HHPPPHPPHH HPPPPPPHHH PPPPHHPPPP HPHPPPHPPH PPPPPPPHPP HPPPPPPPHP HPPPPHPHHH PHHHPHHP...
output:
127
result:
ok single line: '127'
Test #5:
score: 10
Accepted
time: 50ms
memory: 7420kb
input:
40 10 PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPH PPPPPPPPPP PHPPPPPHPP PPPPPPPPPP PPPPPPPPPP PPPPPPPHPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPHPHPPPHP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP HPHPPHPPPP PPPPPPHPPH HPPPPHPPPP PPPPPPPHHP PPPPHPPPPP PPPPPPPPPP PPPPPPPHPP PPPPPPPPPP PPPPPPPPPP PPPHPPPP...
output:
127
result:
ok single line: '127'
Test #6:
score: 10
Accepted
time: 82ms
memory: 10020kb
input:
80 10 PPHPPPPPPP PPPPPPPHPP PHPPPPPPPP PPPPPPPPPP PPPPPPPPPH PPPPPPHPPP PHPPPPPHPP PPPPPPPPPP PPPPPPPPPP PPPHPPPHPP PPPPPPPPPP PPPPPPPPPP PPPPPPHPPP PPHPHPPPHP PPPPPPPPPP PPPPPPPPPP PPPPPPPPHH HPHPPHPHPP PPPHPPHPPH HPPPPHPPPP PPPPPPPHHP PPPPHPPPPP PPPPPPPPPP PPPPPPPHPP PPPPPPPPHP PPPPPPPPPP PPPHPPHP...
output:
244
result:
ok single line: '244'
Test #7:
score: 10
Accepted
time: 74ms
memory: 10340kb
input:
80 10 PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP HHHHHHHHHH PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP HHHHHHHHHH PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP HHHHHHHHHH PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP HHHHHHHHHH PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP HHHHHHHHHH PPPPPPPPPP PPPPPPPP...
output:
216
result:
ok single line: '216'
Test #8:
score: 10
Accepted
time: 20ms
memory: 6988kb
input:
100 10 HHPHPPHHHH HPHPPPHPPH HPHHPPPHPP HPHPPPPHHP PHPPPHHHHP PPHPHPPHHP PPHHHHHPHP PHPHHHHPHH HHPPPPHPHH PPPPHHHPPP PHHPHHHPPH PHHPHPHHPH PHPPPHPPPH HPPHPHHHPP PPPHPPHPHP PPHHHHPPHP HHPPHHPPPP PPPHPPPPPH HPPPPPPHHP PPHPHPHHPP PPPPHHPPPP HHHPPPHHHH PHPPHHPPPP HHHHHHHPHH PPHHHHHHPP PPHPPPHPPP HPPPHPP...
output:
220
result:
ok single line: '220'
Test #9:
score: 10
Accepted
time: 5ms
memory: 4772kb
input:
99 9 PHHPHHPHH HPHHPHHPH HHPHHPHHP PHHPHHPHH HPHHPHHPH HHPHHPHHP PHHPHHPHH HPHHPHHPH HHPHHPHHP PHHPHHPHH HPHHPHHPH HHPHHPHHP PHHPHHPHH HPHHPHHPH HHPHHPHHP PHHPHHPHH HPHHPHHPH HHPHHPHHP PHHPHHPHH HPHHPHHPH HHPHHPHHP PHHPHHPHH HPHHPHHPH HHPHHPHHP PHHPHHPHH HPHHPHHPH HHPHHPHHP PHHPHHPHH HPHHPHHPH HHPHH...
output:
297
result:
ok single line: '297'
Test #10:
score: 10
Accepted
time: 148ms
memory: 13408kb
input:
100 10 PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPHPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PHPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPPPPP PPPPPPP...
output:
333
result:
ok single line: '333'