Submission #485619

#TimeUsernameProblemLanguageResultExecution timeMemory
485619Cross_RatioJOI 문장 (JOI14_ho_t1)C++14
100 / 100
134 ms2368 KiB
#include <bits/stdc++.h> using namespace std; signed main() { cin.sync_with_stdio(false); cin.tie(0); cout.tie(0); int M, N; cin >> M >> N; int i, j; vector<string> S; for(i=0;i<M;i++) { string s; cin >> s; S.push_back(s); } int cnt = 0; string F[2]; cin >> F[0] >> F[1]; for(i=0;i<M-1;i++) { for(j=0;j<N-1;j++) { bool isPos = true; for(int k = 0; k < 4; k++) { if(S[i+k/2][j+k%2]!=F[k/2][k%2]) isPos = false; } if(isPos) cnt++; } } //cout << cnt << '\n'; int ans = cnt; string s3 = "JOI"; for(i=0;i<M;i++) { for(j=0;j<N;j++) { int cnt2 = 0; //cout << i << ' ' << j << '\n'; for(int x = max(0,i-1);x<=min(i,M-2);x++) { for(int y = max(0,j-1);y<=min(j,N-2);y++) { bool isPos = true; for(int k = 0; k < 4; k++) { if(S[x+k/2][y+k%2]!=F[k/2][k%2]) isPos = false; } if(isPos) cnt2++; } } //cout << "Check\n"; char c = S[i][j]; for(int m = 0; m < 3; m++) { S[i][j] = s3[m]; int cnt3 = 0; for(int x = max(0,i-1);x<=min(i,M-2);x++) { for(int y = max(0,j-1);y<=min(j,N-2);y++) { bool isPos = true; for(int k = 0; k < 4; k++) { if(S[x+k/2][y+k%2]!=F[k/2][k%2]) isPos = false; } if(isPos) cnt3++; } } ans = max(ans, cnt - cnt2 + cnt3); } S[i][j] = c; } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...