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;
string s1, s2;
int n, m;
typedef long long ll;
char mat[1005][1005];
char omat[1005][1005];
bool jeste(int i, int j){
if(i <= 0 || j <= 0) return 0;
if(i >= n || j >= m) return 0;
return s1[0] == mat[i][j] && s1[1] == mat[i][j+1] && s2[0] == mat[i+1][j] && s2[1] == mat[i+1][j+1];
}
int main(){
ios_base::sync_with_stdio(false);
cin >> n >> m;
ll res = 0;
for(int i=1; i<=n; i++){
string s;
cin >> s;
for(int j=1; j<=m; j++){
omat[i][j] = mat[i][j] = s[j-1];
}
}
cin >> s1 >> s2;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
res += jeste(i, j);
}
}
ll g = res;
ll poc = res;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
g = poc;
g -= jeste(i-1, j);
g -= jeste(i, j);
g -= jeste(i, j-1);
g -= jeste(i-1, j-1);
ll t = g;
mat[i][j] = 'J';
t += jeste(i-1, j);
t += jeste(i, j);
t += jeste(i, j-1);
t += jeste(i-1, j-1);
res = max(res, t);
t = g;
mat[i][j] = 'O';
t += jeste(i-1, j);
t += jeste(i, j);
t += jeste(i, j-1);
t += jeste(i-1, j-1);
res = max(res, t);
t = g;
mat[i][j] = 'I';
t += jeste(i-1, j);
t += jeste(i, j);
t += jeste(i, j-1);
t += jeste(i-1, j-1);
res = max(res, t);
mat[i][j] = omat[i][j];
}
}
cout << res << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |