# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
244261 | arnold518 | Collecting Mushrooms (NOI18_collectmushrooms) | C++14 | 50 ms | 7188 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int N, M, D, K;
vector<vector<char>> A;
vector<vector<int>> S;
int query(int y1, int x1, int y2, int x2)
{
y1=max(y1, 1); x1=max(x1, 1);
y2=min(y2, N); x2=min(x2, M);
return S[y2][x2]-S[y1-1][x2]-S[y2][x1-1]+S[y1-1][x1-1];
}
int main()
{
int i, j;
scanf("%d%d%d%d", &N, &M, &D, &K);
A=vector<vector<char>>(N+1, vector<char>(M+1));
S=vector<vector<int>>(N+1, vector<int>(M+1));
for(i=1; i<=N; i++) for(j=1; j<=M; j++) scanf(" %c", &A[i][j]);
for(i=1; i<=N; i++)
{
for(j=1; j<=M; j++)
{
S[i][j]=S[i-1][j]+S[i][j-1]-S[i-1][j-1];
if(A[i][j]=='S') S[i][j]++;
}
}
int ans=0;
for(i=1; i<=N; i++) for(j=1; j<=M; j++)
{
if(A[i][j]=='M')
{
if(query(i-D, j-D, i+D, j+D)>=K) ans++;
}
}
printf("%d\n", ans);
}
Compilation message (stderr)
# | 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... |