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;
const int N = 3e3+1;
string S = "RGW";
char c[N][N], tmp[N][N];
bool us[N][N];
int n, m;
bool ver(int i, int j) {
if (j+2 > m) return false;
for (int k=0; k<3; ++k) {
if (c[i][j+k] != S[k] || us[i][j+k]) return false;
}
return true;
}
bool hor(int i, int j) {
if (i+2 > n) return false;
for (int k=0; k<3; ++k) {
if (c[i+k][j] != S[k] || us[i+k][j]) return false;
}
return true;
}
int solve() {
int ans=0;
memset(us, false, sizeof(us));
for (int i=1; i<=n; ++i) {
for (int j=1; j<=m; ++j) {
if (ver(i, j)) {
for (int k=0; k<3; ++k) us[i][j+k]=true;
++ans;
} else if (hor(i, j)) {
for (int k=0; k<3; ++k) us[i+k][j]=true;
++ans;
}
}
}
return ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m;
for (int i=1; i<=n; ++i) {
for (int j=1; j<=m; ++j) cin>>c[i][j];
}
cout<<solve()<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |