QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#505802#4642. 炮兵阵地RainPPR100 ✓148ms13276kbC++201.1kb2024-08-05 11:39:352024-08-05 11:39:36

Judging History

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

  • [2024-08-05 11:39:36]
  • 评测
  • 测评结果:100
  • 用时:148ms
  • 内存:13276kb
  • [2024-08-05 11:39:35]
  • 提交

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

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 0ms
memory: 3624kb

input:

5 4
PHPP
PPHH
PPPP
PHPP
PHHP

output:

6

result:

ok single line: '6'

Test #2:

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

input:

8 4
HPPH
PPPP
HPPH
PHHP
PHHP
HPPH
PPPP
HPPH

output:

8

result:

ok single line: '8'

Test #3:

score: 10
Accepted
time: 38ms
memory: 6584kb

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: 15ms
memory: 6148kb

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: 46ms
memory: 7132kb

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: 9792kb

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: 80ms
memory: 10088kb

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

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: 4784kb

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: 13276kb

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'