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 <stdio.h>
#define N 1000
#define M 1000
int max(int a, int b) { return a > b ? a : b; }
int match(char cc[][M + 1], char aa[][3], int n, int m, int i, int j) {
int i_, j_;
if (i < 0 || j < 0 || i + 1 == n || j + 1 == m)
return 0;
for (i_ = 0; i_ < 2; i_++)
for (j_ = 0; j_ < 2; j_++)
if (cc[i + i_][j + j_] != aa[i_][j_])
return 0;
return 1;
}
int match_(char cc[][M + 1], char aa[][3], int n, int m, int i, int j) {
return match(cc, aa, n, m, i - 1, j - 1) + match(cc, aa, n, m, i - 1, j)
+ match(cc, aa, n, m, i, j - 1) + match(cc, aa, n, m, i, j);
}
int main() {
static char cc[N][M + 1], aa[2][3];
int n, m, i, j, cnt, ans;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++)
scanf("%s", cc[i]);
for (i = 0; i < 2; i++)
scanf("%s", aa[i]);
cnt = 0;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
cnt += match(cc, aa, n, m, i, j);
ans = 0;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++) {
char c = cc[i][j];
int k = match_(cc, aa, n, m, i, j);
cc[i][j] = 'J';
ans = max(ans, cnt - k + match_(cc, aa, n, m, i, j));
cc[i][j] = 'O';
ans = max(ans, cnt - k + match_(cc, aa, n, m, i, j));
cc[i][j] = 'I';
ans = max(ans, cnt - k + match_(cc, aa, n, m, i, j));
cc[i][j] = c;
}
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
2014_ho_t1.c: In function 'main':
2014_ho_t1.c:29:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%d%d", &n, &m);
| ^~~~~~~~~~~~~~~~~~~~~
2014_ho_t1.c:31:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | scanf("%s", cc[i]);
| ^~~~~~~~~~~~~~~~~~
2014_ho_t1.c:33:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | scanf("%s", aa[i]);
| ^~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |