이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |