#include<bits/stdc++.h>
#define taskname "C"
using namespace std;
template<class T>void maximize(T& a, T b){
if(a < b){
a = b;
}
}
int n, m;
namespace sub1{
void solve(){
vector<int>dp(1 << (n * m), -1);
vector<vector<char>>a(n, vector<char>(m));
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin >> a[i][j];
}
}
auto solve = [&] (auto&& self, vector<vector<bool>>state) -> int{
int mask = 0;
for(int i = 0, p = 0; i < n; i++){
for(int j = 0; j < m; j++, p++){
if(state[i][j]){
mask |= 1 << p;
}
}
}
int& ans = dp[mask];
if(ans != -1){
return ans;
}
for(int i = ans = 0; i < n; i++){
for(int j = 0; j + 2 < m; j++){
if(state[i][j] && state[i][j + 1] && state[i][j + 2]){
bool can = true;
for(char c : {'R', 'G', 'W'}){
if(c != a[i][j] && c != a[i][j + 1] && c != a[i][j + 2]){
can = false;
break;
}
}
if(can){
state[i][j] = state[i][j + 1] = state[i][j + 2] = false;
maximize(ans, self(self, state) + 1);
state[i][j] = state[i][j + 1] = state[i][j + 2] = true;
}
}
}
}
for(int i = 0; i + 2 < n; i++){
for(int j = 0; j < m; j++){
if(state[i][j] && state[i + 1][j] && state[i + 2][j]){
bool can = true;
for(char c : {'R', 'G', 'W'}){
if(c != a[i][j] && c != a[i + 1][j] && c != a[i + 2][j]){
can = false;
break;
}
}
if(can){
state[i][j] = state[i + 1][j] = state[i + 2][j] = false;
maximize(ans, self(self, state) + 1);
state[i][j] = state[i + 1][j] = state[i + 2][j] = true;
}
}
}
}
return ans;
};
cout << solve(solve, vector<vector<bool>>(n, vector<bool>(m, true)));
}
}
namespace sub23{
void solve(){
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
cin >> n >> m;
if(n <= 4 && m <= 4){
sub1::solve();
}
else{
sub23::solve();
}
}
Compilation message (stderr)
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:81:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |