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;
void rot90() {
for (int i=1; i<=n; ++i) {
for (int j=1; j<=m; ++j) tmp[j][n-i+1]=c[i][j];
} swap(n, m);
for (int i=1; i<=n; ++i) {
for (int j=1; j<=m; ++j) c[i][j]=tmp[i][j];
}
}
bool ver(int i, int j) {
if (m-j+1 < 3) 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 (n-i+1 < 3) 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<=n; ++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];
}
int k=4, ans=0;
while (k--) {
ans=max(ans, solve());
rot90();
}
cout<<ans<<"\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... |