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<int, int> pii;
const int MX=500010, inf=2e9;
int n, m;
char B[1010][1010], C[3][3];
int A[1010][1010];
int ans=0;
bool flag(int x, int y){
if(x<1 || m<=x || y<1 || n<=y) return false;
for(int i=0; i<=1; i++)
for(int j=0; j<=1; j++)
if(B[x+i][y+j]!=C[i][j]) return false;
return true;
}
int solve(int x, int y, char c){
char prv=B[x][y];
int res=0;
for(int i=-1; i<=0; i++)
for(int j=-1; j<=0; j++)
res-=flag(x+i,y+j);
B[x][y]=c;
for(int i=-1; i<=0; i++)
for(int j=-1; j<=0; j++)
res+=flag(x+i,y+j);
B[x][y]=prv;
return res;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>m>>n;
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++)
cin>>B[i][j];
cin>>C[0][0]>>C[0][1]>>C[1][0]>>C[1][1];
for(int i=1; i<m; i++)
for(int j=1; j<n; j++){
ans+=flag(i,j);
}
int mx=0;
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++){
mx=max(mx, solve(i,j,'J'));
mx=max(mx, solve(i,j,'O'));
mx=max(mx, solve(i,j,'I'));
}
cout<<ans+mx;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |