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;
typedef pair<ll, ll> pll;
const int MAXN = 1000;
int N, M, ans;
char S[MAXN+10][MAXN+10], T[3][3];
int chk(int y, int x)
{
int i, j;
for(i=0; i<2; i++) for(j=0; j<2; j++) if(S[y+i][x+j]!=T[i][j]) return 0;
return 1;
}
int main()
{
int i, j;
scanf("%d%d", &N, &M);
for(i=1; i<=N; i++) scanf("%s", S[i]+1);
for(i=0; i<2; i++) scanf("%s", T[i]);
int cnt=0;
for(i=1; i<=N; i++) for(j=1; j<=M; j++) cnt+=chk(i, j);
ans=cnt;
for(i=1; i<=N; i++) for(j=1; j<=M; j++)
{
char t=S[i][j];
cnt-=chk(i-1, j-1)+chk(i-1, j)+chk(i, j-1)+chk(i, j);
S[i][j]='J';
cnt+=chk(i-1, j-1)+chk(i-1, j)+chk(i, j-1)+chk(i, j);
ans=max(ans, cnt);
cnt-=chk(i-1, j-1)+chk(i-1, j)+chk(i, j-1)+chk(i, j);
S[i][j]='O';
cnt+=chk(i-1, j-1)+chk(i-1, j)+chk(i, j-1)+chk(i, j);
ans=max(ans, cnt);
cnt-=chk(i-1, j-1)+chk(i-1, j)+chk(i, j-1)+chk(i, j);
S[i][j]='I';
cnt+=chk(i-1, j-1)+chk(i-1, j)+chk(i, j-1)+chk(i, j);
ans=max(ans, cnt);
cnt-=chk(i-1, j-1)+chk(i-1, j)+chk(i, j-1)+chk(i, j);
S[i][j]=t;
cnt+=chk(i-1, j-1)+chk(i-1, j)+chk(i, j-1)+chk(i, j);
}
printf("%d", ans);
}
Compilation message (stderr)
2014_ho_t1.cpp: In function 'int main()':
2014_ho_t1.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &M);
~~~~~^~~~~~~~~~~~~~~~
2014_ho_t1.cpp:25:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1; i<=N; i++) scanf("%s", S[i]+1);
~~~~~^~~~~~~~~~~~~~
2014_ho_t1.cpp:26:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=0; i<2; i++) scanf("%s", T[i]);
~~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |