QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#505813 | #4642. 炮兵阵地 | RainPPR | 100 ✓ | 147ms | 13292kb | C++20 | 1.1kb | 2024-08-05 11:48:01 | 2024-08-05 11:48:01 |
Judging History
answer
#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: 3544kb
input:
5 4 PHPP PPHH PPPP PHPP PHHP
output:
6
result:
ok single line: '6'
Test #2:
score: 10
Accepted
time: 1ms
memory: 3484kb
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: 6296kb
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: 19ms
memory: 5796kb
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: 51ms
memory: 7200kb
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: 83ms
memory: 9856kb
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: 82ms
memory: 10092kb
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: 6640kb
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: 6ms
memory: 4776kb
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: 147ms
memory: 13292kb
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'