This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;
const ll maxn=3e3+5;
const int INF=1e9;
#define ok ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define endl '\n'
int n, m, ls, ans, ans2;
bool use[maxn][maxn];
char grid[maxn][maxn];
int main() {
ok
cin >> n >> m;
for(int i=0; i<n; i++) {
for(int j=0; j<m; j++) {
cin >> grid[i][j];
}
}
for(int i=0; i<n; i++) {
for(int j=0; j<m-2; j++) {
if(grid[i][j]=='R' && grid[i][j+1]=='G' && grid[i][j+2]=='W' && !use[i][j] && !use[i][j+1] && !use[i][j+2]) {
ans++;
use[i][j]=1;
use[i][j+1]=1;
use[i][j+2]=1;
}
}
if(ls<m) {
for(int j=0; j<n-2; j++) {
if(grid[j][ls]=='R' && grid[j+1][ls]=='G' && grid[j+2][ls]=='W' && !use[j][ls] && !use[j+1][ls] && !use[j+2][ls]) {
ans++;
use[j][ls]=1;
use[j+1][ls]=1;
use[j+2][ls]=1;
}
}
ls++;
}
}
for(int i=ls; i<m; i++) {
for(int j=0; j<n-2; j++) {
if(grid[j][ls]=='R' && grid[j+1][ls]=='G' && grid[j+2][ls]=='W' && !use[j][ls] && !use[j+1][ls] && !use[j+2][ls]) {
ans++;
use[j][ls]=1;
use[j+1][ls]=1;
use[j+2][ls]=1;
}
}
}
ls=0;
memset(use, 0, sizeof use);
for(int i=0; i<m; i++) {
for(int j=0; j<n-2; j++) {
if(grid[j][i]=='R' && grid[j+1][i]=='G' && grid[j+2][i]=='W' && !use[j][i] && !use[j+1][i] && !use[j+2][i]) {
ans2++;
use[j][i]=1;
use[j+1][i]=1;
use[j+2][i]=1;
}
}
if(ls<n) {
for(int j=0; j<m-2; j++) {
if(grid[ls][j]=='R' && grid[ls][j+1]=='G' && grid[ls][j+2]=='W' && !use[ls][j] && !use[ls][j+1] && !use[ls][j+2]) {
ans2++;
use[ls][j]=1;
use[ls][j+1]=1;
use[ls][j+2]=1;
}
}
ls++;
}
}
for(int i=ls; i<n; i++) {
for(int j=0; j<m-2; j++) {
if(grid[i][j]=='R' && grid[i][j+1]=='G' && grid[i][j+2]=='W' && !use[i][j] && !use[i][j+1] && !use[i][j+2]) {
ans2++;
use[i][j]=1;
use[i][j+1]=1;
use[i][j+2]=1;
}
}
}
cout << max(ans, ans2);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |