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 <iostream>
#include <cstdio>
using namespace std;
int n, m, s, mx, d[1005][1005];
char t, a[1005][1005], b[2][2], c[3] = {'J', 'O', 'I'};
int f(int p, int q) {
return (a[p][q] == b[0][0] && a[p][q + 1] == b[0][1] && a[p + 1][q] == b[1][0] && a[p + 1][q + 1] == b[1][1]);
}
int main()
{
int i, j, k, z;
cin >> n >> m;
for (i= 1; i <= n; i++) {
scanf ("%s", &a[i][1]);
}
cin >> b[0] >> b[1];
for (i = 1; i < n; i++) {
for (j = 1; j < m; j++) {
z = f(i, j);
s += z;
d[i][j] = z;
}
}
mx = s;
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
t = a[i][j];
for (k = 0; k < 3; k++) {
a[i][j] = c[k];
mx = max(mx, s - d[i - 1][j - 1] - d[i - 1][j] - d[i][j - 1] - d[i][j] + f(i - 1, j - 1) + f(i - 1, j) + f(i, j - 1) + f(i, j));
}
a[i][j] = t;
}
}
cout << mx;
return 0;
}
Compilation message (stderr)
2014_ho_t1.cpp: In function 'int main()':
2014_ho_t1.cpp:15:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%s", &a[i][1]);
~~~~~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |