제출 #1339520

#제출 시각아이디문제언어결과실행 시간메모리
1339520luvqroseCollecting Mushrooms (NOI18_collectmushrooms)C++20
38 / 100
18 ms14636 KiB
#include <bits/stdc++.h>

using namespace std;

const int nx=5e5+5;
int n, m, d, k, ans;
vector<pair<int,int>> s, mush;
char a;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>m>>d>>k;
    vector<vector<int>> sw1(n+2, vector<int> (m+2)), sw2(n+2, vector<int> (m+2));
    vector<vector<char>> mp(n+2, vector<char> (m+2));
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=m; j++)
        {
            cin>>mp[i][j];
            if (mp[i][j]=='S')
            {
                sw1[max(0, i-d)][max(0, j-d)]++;
                sw1[min(n+1, i+d+1)][max(0, j-d)]--;
                sw1[max(0, i-d)][min(m+1, j+d+1)]--;
                sw1[min(n+1, i+d+1)][min(m+1, i+d+1)]++;
            }
            if (a=='M') mush.push_back({i, j});
        }
    }
    for (int i=1; i<=n; i++)
    {
        for (int j=0; j<=m; j++)
        {
            sw1[i][j]+=sw1[i-1][j];
        }
    }
    for (int i=1; i<=n; i++)
    {
        for (int j=0; j<=m; j++)
        {
            sw1[i][j]+=sw1[i][j-1];
        }
    }
    for (int i=1; i<=n; i++)
    {
        for (int j=1; j<=m; j++)
        {
            if (mp[i][j]=='M' && sw1[i][j]>=k) ans++;
        }
    }
    cout<<ans;
}
#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...