Submission #448252

#TimeUsernameProblemLanguageResultExecution timeMemory
448252JovanBJOI 문장 (JOI14_ho_t1)C++17
100 / 100
118 ms3400 KiB
#include <bits/stdc++.h> using namespace std; string s1, s2; int n, m; typedef long long ll; char mat[1005][1005]; char omat[1005][1005]; bool jeste(int i, int j){ if(i <= 0 || j <= 0) return 0; if(i >= n || j >= m) return 0; return s1[0] == mat[i][j] && s1[1] == mat[i][j+1] && s2[0] == mat[i+1][j] && s2[1] == mat[i+1][j+1]; } int main(){ ios_base::sync_with_stdio(false); cin >> n >> m; ll res = 0; for(int i=1; i<=n; i++){ string s; cin >> s; for(int j=1; j<=m; j++){ omat[i][j] = mat[i][j] = s[j-1]; } } cin >> s1 >> s2; for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ res += jeste(i, j); } } ll g = res; ll poc = res; for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ g = poc; g -= jeste(i-1, j); g -= jeste(i, j); g -= jeste(i, j-1); g -= jeste(i-1, j-1); ll t = g; mat[i][j] = 'J'; t += jeste(i-1, j); t += jeste(i, j); t += jeste(i, j-1); t += jeste(i-1, j-1); res = max(res, t); t = g; mat[i][j] = 'O'; t += jeste(i-1, j); t += jeste(i, j); t += jeste(i, j-1); t += jeste(i-1, j-1); res = max(res, t); t = g; mat[i][j] = 'I'; t += jeste(i-1, j); t += jeste(i, j); t += jeste(i, j-1); t += jeste(i-1, j-1); res = max(res, t); mat[i][j] = omat[i][j]; } } cout << res << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...