Submission #1247860

#TimeUsernameProblemLanguageResultExecution timeMemory
1247860tvgkJOI 문장 (JOI14_ho_t1)C++20
100 / 100
58 ms1352 KiB
#include<bits/stdc++.h>
using namespace std;
#define task "a"
#define se second
#define fi first
#define ll long long
#define ii pair<ll, ll>
const long mxN = 1e3 + 7;

int nRow, nCol;
string s[mxN], f[3];
vector<char> chr = {'J', 'O', 'I'};

bool cmp(int i, int j)
{
    if (i < 0 || j < 0)
        return 0;

    int iden = 0;
    for (int u = 0; u <= 1; u++)
    {
        for (int v = 0; v <= 1; v++)
            iden += (f[u][v] == s[i + u][j + v]);
    }
    return iden == 4;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(task".INP", "r", stdin);
    //freopen(task".OUT", "w", stdout);

    cin >> nRow >> nCol;
    for (int i = 0; i < nRow; i++)
        cin >> s[i];
    cin >> f[0];
    cin >> f[1];

    int cnt = 0;
    for (int i = 0; i < nRow - 1; i++)
    {
        for (int j = 0; j < nCol - 1; j++)
            cnt += cmp(i, j);
    }

    int ans = cnt;
    for (int i = 0; i < nRow; i++)
    {
        for (int j = 0; j < nCol; j++)
        {
            char mem = s[i][j];

            int down = 0;
            for (int u = -1; u <= 0; u++)
            {
                for (int v = -1; v <= 0; v++)
                    down += cmp(i + u, j + v);
            }

            for (char nw : chr)
            {
                s[i][j] = nw;
                int up = 0;
                for (int u = -1; u <= 0; u++)
                {
                    for (int v = -1; v <= 0; v++)
                        up += cmp(i + u, j + v);
                }
                ans = max(ans, cnt - down + up);
            }
            s[i][j] = mem;
        }
    }
    cout << ans;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...