#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
using namespace std;
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define vc vector
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define int ll
const int N = 3005;
const int M = 3005;
const int mod = 1e9 + 7;
const int block = 500;
int n, m;
char a[N][N];
bool used[N][N];
int tp[N][N];
void solve() {
cin >> n >> m;
for ( int i = 1; i <= n; i++ ) {
for ( int j = 1; j <= m; j++ ) {
cin >> a[i][j];
}
}
int k = n * m, res = 0;
for ( int i = 0; i < (1<<k); i++ ) {
for ( int i = 1; i <= n; i++ ) {
for ( int j = 1; j <= m; j++ ) {
used[i][j] = 0;
tp[i][j] = 0;
}
}
vc <int> save;
for ( int p = 0; p < k; p++ ) {
if ( ( i >> p ) & 1 ) {
save.pb(p);
}
}
if ( sz(save) > k / 3 ) {
continue;
}
for ( auto p : save ) {
for ( int j = 0; j < ( 1 << k ); j++ ) {
int x = p / n + 1, y = ( p % m + 1 );
if ( ( j >> p ) & 1 ) {
tp[x][y] = 2;
}
else {
tp[x][y] = 1;
}
}
}
bool ok = 1;
for ( int x = 1; x <= n; x++ ) {
for ( int y = 1; y <= m; y++ ) {
if ( tp[x][y] == 1 ) {
string s = "";
s += a[x][y]; s += a[x][y+1]; s += a[x][y+2];
if ( y + 2 > m || used[x][y] || used[x][y+1] || used[x][y+2] || s != "RGW" ) ok = 0;
else {
used[x][y] = 1;
used[x][y+1] = 1;
used[x][y+2] = 1;
}
}
else if ( tp[x][y] == 2 ) {
string s = "";
s += a[x][y]; s += a[x+1][y]; s += a[x+2][y];
if ( x + 2 > n || used[x][y] || used[x+1][y] || used[x+2][y] || s != "RGW" ) ok = 0;
else {
used[x][y] = 1;
used[x+1][y] = 1;
used[x+2][y] = 1;
}
}
}
}
if ( ok ) res = max(res,sz(save));
}
cout << res;
}
signed main() {
speed;
int tt;
//cin >> tt;
tt = 1;
while ( tt-- ) {
solve();
cout << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4556 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
10 ms |
4576 KB |
Output is correct |
6 |
Correct |
12 ms |
4440 KB |
Output is correct |
7 |
Correct |
10 ms |
4580 KB |
Output is correct |
8 |
Correct |
10 ms |
4580 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4556 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
10 ms |
4576 KB |
Output is correct |
6 |
Correct |
12 ms |
4440 KB |
Output is correct |
7 |
Correct |
10 ms |
4580 KB |
Output is correct |
8 |
Correct |
10 ms |
4580 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4556 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
10 ms |
4576 KB |
Output is correct |
6 |
Correct |
12 ms |
4440 KB |
Output is correct |
7 |
Correct |
10 ms |
4580 KB |
Output is correct |
8 |
Correct |
10 ms |
4580 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |