Submission #1082336

# Submission time Handle Problem Language Result Execution time Memory
1082336 2024-08-31T07:40:06 Z vuavisao Collecting Mushrooms (NOI18_collectmushrooms) C++14
100 / 100
15 ms 29788 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;

using ll = long long;

const int N = 500'000 + 10;

int numRows, numCols, dist, cnt;
string s[N];

vector<vector<int>> pred;

int32_t main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr); std::cout.tie(nullptr);
	cin >> numRows >> numCols >> dist >> cnt;
	pred.resize(numRows + 5, vector<int>(numCols + 5, 0));
	for (int i = 1; i <= numRows; ++ i) {
		cin >> s[i]; s[i] = ' ' + s[i];
		for (int j = 1; j <= numCols; ++ j) {
			if (s[i][j] == 'S') {
				int le = max(1, j - dist);
				int ri = min(numCols, j + dist);
				int up = max(1, i - dist);
				int down = min(numRows, i + dist);
				++ pred[up][le];
				-- pred[up][ri + 1];
				-- pred[down + 1][le];
				++ pred[down + 1][ri + 1];
			}
		}
	}
	int res = 0;
	for (int i = 1; i <= numRows; ++ i) {
		for (int j = 1; j <= numCols; ++ j) {
			pred[i][j] += pred[i - 1][j] + pred[i][j - 1] - pred[i - 1][j - 1];
			if (s[i][j] == 'M' && pred[i][j] >= cnt) ++ res;
		}
	}
	cout << res;
	return (0 ^ 0);
}

/// Code by vuavisao
# Verdict Execution time Memory Grader output
1 Correct 3 ms 15964 KB Output is correct
2 Correct 3 ms 15964 KB Output is correct
3 Correct 3 ms 15960 KB Output is correct
4 Correct 3 ms 15964 KB Output is correct
5 Correct 3 ms 15964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 15964 KB Output is correct
2 Correct 3 ms 15964 KB Output is correct
3 Correct 3 ms 15960 KB Output is correct
4 Correct 3 ms 15964 KB Output is correct
5 Correct 3 ms 15964 KB Output is correct
6 Correct 3 ms 15960 KB Output is correct
7 Correct 4 ms 15964 KB Output is correct
8 Correct 3 ms 15960 KB Output is correct
9 Correct 3 ms 15964 KB Output is correct
10 Correct 2 ms 15964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 15964 KB Output is correct
2 Correct 3 ms 15964 KB Output is correct
3 Correct 3 ms 15964 KB Output is correct
4 Correct 3 ms 15964 KB Output is correct
5 Correct 4 ms 15964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 17244 KB Output is correct
2 Correct 4 ms 17244 KB Output is correct
3 Correct 4 ms 17516 KB Output is correct
4 Correct 4 ms 17276 KB Output is correct
5 Correct 4 ms 17272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 29788 KB Output is correct
2 Correct 10 ms 29788 KB Output is correct
3 Correct 11 ms 29788 KB Output is correct
4 Correct 15 ms 29784 KB Output is correct
5 Correct 13 ms 29788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 15964 KB Output is correct
2 Correct 3 ms 15964 KB Output is correct
3 Correct 3 ms 15960 KB Output is correct
4 Correct 3 ms 15964 KB Output is correct
5 Correct 3 ms 15964 KB Output is correct
6 Correct 3 ms 15960 KB Output is correct
7 Correct 4 ms 15964 KB Output is correct
8 Correct 3 ms 15960 KB Output is correct
9 Correct 3 ms 15964 KB Output is correct
10 Correct 2 ms 15964 KB Output is correct
11 Correct 3 ms 15964 KB Output is correct
12 Correct 3 ms 15964 KB Output is correct
13 Correct 3 ms 15964 KB Output is correct
14 Correct 3 ms 15964 KB Output is correct
15 Correct 4 ms 15964 KB Output is correct
16 Correct 6 ms 17244 KB Output is correct
17 Correct 4 ms 17244 KB Output is correct
18 Correct 4 ms 17516 KB Output is correct
19 Correct 4 ms 17276 KB Output is correct
20 Correct 4 ms 17272 KB Output is correct
21 Correct 14 ms 29788 KB Output is correct
22 Correct 10 ms 29788 KB Output is correct
23 Correct 11 ms 29788 KB Output is correct
24 Correct 15 ms 29784 KB Output is correct
25 Correct 13 ms 29788 KB Output is correct
26 Correct 10 ms 20824 KB Output is correct
27 Correct 7 ms 19036 KB Output is correct
28 Correct 8 ms 19292 KB Output is correct
29 Correct 7 ms 19124 KB Output is correct
30 Correct 9 ms 20016 KB Output is correct