Submission #95761

#TimeUsernameProblemLanguageResultExecution timeMemory
95761easruiJOI 문장 (JOI14_ho_t1)C++14
100 / 100
184 ms6392 KiB
#include <bits/stdc++.h> using namespace std; const int MAX = 1e3+5; int M,N,ans,res,tmp; char F[MAX][MAX],K[2][2],B[3]={'J','O','I'}; int C[MAX][MAX]; int match(int a, int b, int x, int y, char c) { if(a<1 || a>=M || b<1 || b>=N) return 0; for(int i=0; i<2; i++) for(int j=0; j<2; j++) { if(a+i==x && b+j==y) { if(c!=K[i][j]) return 0; } else if(F[a+i][b+j]!=K[i][j]) return 0; } return 1; } int main() { //freopen("input.txt","r",stdin); ios_base::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 >> F[i][j]; for(int i=0; i<2; i++) for(int j=0; j<2; j++) cin >> K[i][j]; for(int i=0; i<=M; i++) for(int j=0; j<=N; j++) { C[i][j] = match(i,j,i,j,F[i][j]); tmp += C[i][j]; } ans = tmp; for(int i=1; i<=M; i++) for(int j=1; j<=N; j++) for(int k=0; k<3; k++) { res = 0; for(int x=-1; x<=0; x++) for(int y=-1; y<=0; y++) res += match(i+x,j+y,i,j,B[k]) - C[i+x][j+y]; ans = max(ans,tmp+res); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...