/* Ajay Jadhav */
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <ctime>
#include <string.h>
#include <climits>
#include <cstring>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define sz(x) (int)x.size()
#define hell 1000000007
#define rep(i, a, b) for (int i = a; i < b; i++)
#define endl '\n'
void solve()
{
int r, c, d, k;
cin >> r >> c >> d >> k;
int dx[8] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
vector<string> field(r);
vvi mat(r, vi(c));
vvi mushrooms, sprinkler;
rep(i, 0, r)
{
cin >> field[i];
rep(j, 0, c)
{
if (field[i][j] == 'M')
mushrooms.pb({i, j});
else if (field[i][j] == 'S')
sprinkler.pb({i, j});
}
}
queue<vi> que;
rep(i, 0, sz(sprinkler))
{
sprinkler[i].pb(d);
que.push(sprinkler[i]);
}
while (!que.empty())
{
vi cur = que.front();
que.pop();
mat[cur[0]][cur[1]]++;
if (cur[2] > 0)
{
rep(i, 0, 8)
{
int newx = cur[0] + dx[i];
int newy = cur[1] + dy[i];
if (newx >= 0 and newx < r and newy >= 0 and newy < c)
{
que.push({newx, newy, cur[2] - 1});
}
}
}
}
int ans = 0;
rep(i, 0, sz(mushrooms))
{
if (mat[mushrooms[i][0]][mushrooms[i][1]] >= k)
{
ans++;
}
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>>t;
while (t--)
{
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
231 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
231 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
704 KB |
Output is correct |
2 |
Correct |
2 ms |
1492 KB |
Output is correct |
3 |
Correct |
2 ms |
1040 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
209 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
474 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
231 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |