제출 #485428

#제출 시각아이디문제언어결과실행 시간메모리
485428blueCollecting Mushrooms (NOI18_collectmushrooms)C++17
18 / 100
11 ms14992 KiB
#include <iostream>
#include <vector>
using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int R, C, D, K;
    cin >> R >> C >> D >> K;

    string S[1+R];
    for(int i = 1; i <= R; i++)
    {
        cin >> S[i];
        S[i] = " " + S[i];
    }

    vvi delta(1+R+1, vi(1+C+1, 0));

    for(int i = 1; i <= R; i++)
    {
        for(int j = 1; j <= C; j++)
        {
            if(S[i][j] != 'S') continue;

            int i_lo = max(1, i - K);
            int j_lo = max(1, j - K);
            int i_hi = min(R, i + K);
            int j_hi = min(C, j + K);

            delta[i_lo][j_lo]++;
            delta[i_hi+1][j_hi+1]++;
            delta[i_lo][j_hi+1]--;
            delta[i_hi+1][j_lo]--;
        }
    }

    int ans = 0;

    vvi tot(1+R+1, vi(1+C+1, 0));
    for(int i = 1; i <= R; i++)
    {
        for(int j = 1; j <= C; j++)
        {
            tot[i][j] = tot[i][j-1] + tot[i-1][j] - tot[i-1][j-1] + delta[i][j];
            if(tot[i][j] >= K && S[i][j] == 'M') ans++;
        }
    }

    cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...