QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#502654 | #4642. 炮兵阵地 | Ephemeron | 100 ✓ | 29ms | 4640kb | C++14 | 1.9kb | 2024-08-03 10:56:49 | 2024-08-03 10:56:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
bool Mbe;
constexpr int N = 1e2 + 9;
constexpr int M = 1 << 10;
constexpr double eps = 1e-5;
constexpr int mod = 1e8;
constexpr int inf = 0x3f3f3f3f;
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rnd(2024);
int rd(int l, int r) {
return rnd() % (r - l + 1) + l;
}
int read();
void write(ll x);
int n, m, s[M], cnt, g[N], num[M], f[2][M][M];
bool Med;
/*------------------------------------------------------------------------*/
int main() {
fprintf(stderr, "%.3lf MB\n", (&Mbe - &Med) / 1048576.0);
ios::sync_with_stdio(0), cin.tie(nullptr), cout.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < m; j++) {
char ch; cin >> ch;
if (ch == 'P') g[i] += (1 << m - j - 1);
}
}
for (int i = 0; i < (1 << m); i++) {
if (!(i & i << 1) && !(i & i << 2)) {
s[cnt++] = i;
num[i] = __builtin_popcount(i);
}
}
for (int i = 1; i <= n + 2; i++)
for (int a = 0; a < cnt; a++)
for (int b = 0; b < cnt; b++)
for (int c = 0; c < cnt; c++)
if (!(s[a] & s[b]) && !(s[b] & s[c]) && !(s[a] & s[c]) && (s[a] & g[i]) == s[a] && (s[b] & g[i - 1]) == s[b])
f[i & 1][a][b] = max(f[i & 1][a][b], f[i - 1 & 1][b][c] + num[s[a]]);
cout << f[n + 2 & 1][0][0];
cerr << "\n" << 1e3 * clock() / CLOCKS_PER_SEC << " ms\n";
return 0;
}
/*------------------------------------------------------------------------*/
int read() {
int x = 0, w = 1;
char ch = 0;
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + (ch - '0');
ch = getchar();
}
return x * w;
}
void write(ll x) {
if (x < 0) x = -x, putchar('-');
static int sta[35];
int top = 0;
do {
sta[top++] = x % 10, x /= 10;
} while (x);
while (top) putchar(sta[--top] + 48);
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 1ms
memory: 3972kb
input:
5 4 PHPP PPHH PPPP PHPP PHHP
output:
6
result:
ok single line: '6'
Test #2:
score: 10
Accepted
time: 0ms
memory: 3964kb
input:
8 4 HPPH PPPP HPPH PHHP PHHP HPPH PPPP HPPH
output:
8
result:
ok single line: '8'
Test #3:
score: 10
Accepted
time: 10ms
memory: 4640kb
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: 11ms
memory: 4464kb
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: 12ms
memory: 4496kb
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: 24ms
memory: 4400kb
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: 23ms
memory: 4392kb
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: 26ms
memory: 4344kb
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: 8ms
memory: 4100kb
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: 29ms
memory: 4396kb
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'