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 MXN = 1005;
char A[MXN][MXN], c[5][5];
int n, m;
int ck(int x,int y){
int o = 1;
for(int i = 0;i<2;i++) for(int j = 0;j<2;j++)
if(A[x+i-1][y+j-1]!=c[i][j]) o = 0;
return o;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for(int i = 0;i<n;i++){
for(int j = 0;j<m;j++)
cin >> A[i][j];
}
for(int i = 0;i<2;i++)
for(int j = 0;j<2;j++)
cin >> c[i][j];
int cnt = 0;
for(int i = 1;i<n;i++)
for(int j = 1;j<m;j++){
cnt += ck(i,j);
}
string L = "JOI";
int ans = 0;
for(int i = 0;i<n;i++){
for(int j = 0;j<m;j++){
char k = A[i][j];
int down = 0, up = 0;
for(int di = 0;di<2;di++) for(int dj = 0;dj<2;dj++)
if(i+di && j+dj && i+di!=n && j+dj!=m) down += ck(i+di,j+dj);
for(auto l : L) {
A[i][j] = l;
for(int di = 0;di<2;di++) for(int dj = 0;dj<2;dj++)
if(i+di && j+dj && i+di!=n && j+dj!=m) up += ck(i+di,j+dj);
ans = max(ans,cnt-down+up);
}
A[i][j] = k;
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |