QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#502586#4642. 炮兵阵地RainPPR100 ✓45ms27300kbC++201.0kb2024-08-03 09:53:512024-08-03 09:53:52

Judging History

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

  • [2024-08-03 09:53:52]
  • 评测
  • 测评结果:100
  • 用时:45ms
  • 内存:27300kb
  • [2024-08-03 09:53:51]
  • 提交

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);
	}
}

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;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 1ms
memory: 3632kb

input:

5 4
PHPP
PPHH
PPPP
PHPP
PHHP

output:

6

result:

ok single line: '6'

Test #2:

score: 10
Accepted
time: 1ms
memory: 3728kb

input:

8 4
HPPH
PPPP
HPPH
PHHP
PHHP
HPPH
PPPP
HPPH

output:

8

result:

ok single line: '8'

Test #3:

score: 10
Accepted
time: 9ms
memory: 9812kb

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: 3ms
memory: 8232kb

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: 3ms
memory: 11924kb

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: 16ms
memory: 18496kb

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: 18ms
memory: 19020kb

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: 4ms
memory: 10008kb

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: 0ms
memory: 6784kb

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: 45ms
memory: 27300kb

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'