Submission #853387

# Submission time Handle Problem Language Result Execution time Memory
853387 2023-09-24T09:14:12 Z annabeth9680 Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
8 ms 3400 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 11;
char grid[MAXN];
int dp[MAXN];
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int R,C,D,K; cin >> R >> C >> D >> K;
	for(int i = 0;i<R;++i){
        for(int j = 0;j<C;++j){
            cin >> grid[i*C+j];
            if(grid[i*C+j] == 'S'){
                int minr = max(i-D,0), maxr = min(i+D,R-1), minc = max(j-D,0), maxc = min(j+D,C-1);
                dp[minr*C+minc]++;
                if(maxr != R-1) dp[(maxr+1)*C+minc]--;
                if(maxc != C-1) dp[minr*C+maxc+1]--;
                if(maxr != R-1 && maxc != C-1) dp[(maxr+1)*C+maxc+1]++;
            }
        }
	}
	int ans = 0;
	for(int i = 0;i<R;++i){
        for(int j = 0;j<C;++j){
            if(i) dp[i*C+j] += dp[(i-1)*C+j];
            if(j) dp[i*C+j] += dp[i*C+j-1];
            if(i > 0 && j > 0) dp[i*C+j] -= dp[(i-1)*C+j-1];
            if(dp[i*C+j] >= K && grid[i*C+j] == 'M'){
                //cout << i << " " << j << "\n";
                ans++;
            }
        }
	}
	cout << ans << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2652 KB Output is correct
2 Correct 3 ms 2652 KB Output is correct
3 Correct 4 ms 2860 KB Output is correct
4 Correct 3 ms 2908 KB Output is correct
5 Correct 3 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 3164 KB Output is correct
2 Correct 7 ms 3400 KB Output is correct
3 Correct 7 ms 3164 KB Output is correct
4 Correct 8 ms 3164 KB Output is correct
5 Correct 7 ms 3396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 3 ms 2652 KB Output is correct
17 Correct 3 ms 2652 KB Output is correct
18 Correct 4 ms 2860 KB Output is correct
19 Correct 3 ms 2908 KB Output is correct
20 Correct 3 ms 2908 KB Output is correct
21 Correct 7 ms 3164 KB Output is correct
22 Correct 7 ms 3400 KB Output is correct
23 Correct 7 ms 3164 KB Output is correct
24 Correct 8 ms 3164 KB Output is correct
25 Correct 7 ms 3396 KB Output is correct
26 Correct 8 ms 3164 KB Output is correct
27 Correct 7 ms 3164 KB Output is correct
28 Correct 8 ms 3164 KB Output is correct
29 Correct 8 ms 3164 KB Output is correct
30 Correct 8 ms 3364 KB Output is correct