This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#include <unordered_map>
#define ll long long
#define int long long
#define all(v) v.begin(), v.end()
#define nl '\n'
#define pb push_back
#define sz(s) (int)(s).size()
#define f first
#define s second
using namespace std;
const ll N = 5e5 + 50, MX = 5e18;
void solve(){
ll n, m;
cin >> n >> m;
char a[n * m];
for(int i = 0; i < n*m; i++){
cin >> a[i];
}
ll ans = 0;
for(ll mask = 0; mask < (1 << (n * m)); mask++){
char b[n * m];
for(int i = 0; i < n*m; i++){
b[i] = a[i];
}
ll col = 0;
ll lst2=-1, lst1=-1, cur=-1;
for(int i = 0; i < n*m; i++){
for(int j = i; j < (1+(i / m)) * m; j++){
if ((mask >> j) & 1) {
lst2 = lst1;
lst1 = cur;
cur = j;
if (mask == 2181 && i == 11) {
//cout << lst2 << " " << lst1 << " " << cur << nl;
}
if (lst2 != -1) {
if (cur - lst1 == 1 && lst1 - lst2 == 1 && a[cur] == 'W' && a[lst1] == 'G' && a[lst2] == 'R') {
col++;
a[cur] = a[lst1] = a[lst2] = 'z';
cur = lst1 = lst2 = -1;
if (mask == 3983 && i == 2) {
//cout << "GAYYY" << nl;
}
}
if (cur - lst1 == m && lst1 - lst2 == m && a[cur] == 'W' && a[lst1] == 'G' && a[lst2] == 'R') {
col++;
if (mask == 3983 && i == 11) {
//cout << "GAYYY" << nl;
}
a[cur] = a[lst1] = a[lst2] = 'z';
cur = lst1 = lst2 = -1;
}
}
if (mask == 3983 && i == 10) {
//cout << lst2 << " " << lst1 << " " << cur << nl;
//cout << col << nl;
}
}
}
ll j = i;
while(j < n * m){
if ((mask >> i) & 1) {
lst2 = lst1;
lst1 = cur;
cur = j;
if (mask == 2181 && i == 11) {
//cout << lst2 << " " << lst1 << " " << cur << nl;
}
if (lst2 != -1) {
if (cur - lst1 == 1 && lst1 - lst2 == 1 && a[cur] == 'W' && a[lst1] == 'G' && a[lst2] == 'R') {
col++;
a[cur] = a[lst1] = a[lst2] = 'z';
cur = lst1 = lst2 = -1;
if (mask == 3983 && i == 2) {
//cout << "GAYYY" << nl;
}
}
if (cur - lst1 == m && lst1 - lst2 == m && a[cur] == 'W' && a[lst1] == 'G' && a[lst2] == 'R') {
col++;
if (mask == 3983 && i == 11) {
//cout << "GAYYY" << nl;
}
a[cur] = a[lst1] = a[lst2] = 'z';
cur = lst1 = lst2 = -1;
}
}
if (mask == 3983 && i == 10) {
//cout << lst2 << " " << lst1 << " " << cur << nl;
//cout << col << nl;
}
}
j += m;
}
}
for(int i = 0; i < n*m; i++){
a[i] = b[i];
}
ans = max(ans, col);
}
cout << ans << nl;
}
signed main(){
//freopen("lca.in", "r", stdin);
//freopen("lca.out", "w", stdout);
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll ql=1;
//cin >> ql;
//tst++;
while(ql--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |