Submission #98409

#TimeUsernameProblemLanguageResultExecution timeMemory
98409314rateCollecting Mushrooms (NOI18_collectmushrooms)C++14
100 / 100
45 ms32908 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

int main()
{
        ///freopen("aaaaa", "r", stdin);
        ///freopen("bbbbb", "w", stdout);
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int n, m, d, k;
        cin >> n >> m >> d >> k;
        vector<vector<int>>v(n + 7);
        vector<vector<int>>a(n + 7);
        for(int i = 0; i < n + 7; i++)
        {
                v[i].resize(m + 7, 0);
                a[i].resize(m + 7, 0);
        }
        for(int i = 1; i <= n; i++)
        {
                string s;
                cin >> s;
                for(int j = 1; j <= m; j++)
                {
                        if(s[j - 1] == '.') v[i][j] = 0;
                        if(s[j - 1] == 'M') v[i][j] = 1;
                        if(s[j - 1] == 'S') v[i][j] = 2;
                }
        }
        for(int i = 1; i <= n; i++)
        {
                for(int j = 1; j <= m; j++)
                {
                        if(v[i][j] == 2)
                        {
                                int rmi = i - d;
                                int rma = i + d;
                                int cmi = j - d;
                                int cma = j + d;
                                if(rmi < 1) rmi = 1;
                                if(cmi < 1) cmi = 1;
                                if(rma > n + 1) rma = n + 1;
                                if(cma > m + 1) cma = m + 1;
                                a[rmi][cmi]++;
                                a[rmi][cma + 1]--;
                                a[rma + 1][cmi]--;
                                a[rma + 1][cma + 1]++;
                        }
                }
        }
        for(int i = 1; i <= n; i++)
        {
                for(int j = 1; j <= m; j++)
                {
                        a[i][j] += a[i][j - 1];
                }
        }
        for(int i = 1; i <= n; i++)
        {
                for(int j = 1; j <= m; j++)
                {
                        a[i][j] += a[i - 1][j];
                }
        }
        int r = 0;
        for(int i = 1; i <= n; i++)
        {
                for(int j = 1; j <= m; j++)
                {
                        if(v[i][j] == 1 && a[i][j] >= k)
                        {
                                r++;
                        }
                }
        }
        cout << r << "\n";
        return 0;
}
/**

**/
#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...