Submission #925983

# Submission time Handle Problem Language Result Execution time Memory
925983 2024-02-12T12:18:49 Z vjudge1 Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
17 ms 10052 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define emb emplace_back
#define emc emplace
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
template <class type_key, class type_val>
using um = unordered_map<type_key, type_val>;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct coordinate {
	int x{}, y{};
	coordinate() = default;
	coordinate( int _x, int _y ) {
		x = _x, y = _y;
	}
};

signed main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

	int n, m, d, k;
	cin >> n >> m >> d >> k;

	int pref[n+1][m+1];
	for( int i = 0; i <= n; i++ )
		pref[i][0] = pref[0][i] = 0;

	vector<coordinate> msh;
	for( int i = 1; i <= n; i ++ ) {
		for( int j = 1; j <= m; j++ ) {
			char c;
			cin >> c;
			pref[i][j] = pref[i-1][j] + pref[i][j-1] - pref[i-1][j-1];
			pref[i][j] += (c == 'S');
			if( c == 'M') {
				msh.pb(coordinate(i,j));
			}
		}
	}

	int ans = 0;
	for( int i = 0; i < msh.size(); i++ ) {
		int x1, y1, x2, y2;
		x1 = max(msh[i].x - d, 1);
		y1 = max(msh[i].y - d, 1);
		x2 = min(msh[i].x + d, n);
		y2 = min(msh[i].y + d, m);

		int cnt = pref[x2][y2] - pref[x2][y1-1] - pref[x1-1][y2] + pref[x1-1][y1-1];
		if( cnt >= k ) {
			ans++;
		}
	}
	cout << ans;

return 0;
}

Compilation message

mushrooms.cpp: In function 'int main()':
mushrooms.cpp:56:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<coordinate>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |  for( int i = 0; i < msh.size(); i++ ) {
      |                  ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1116 KB Output is correct
2 Correct 4 ms 1116 KB Output is correct
3 Correct 3 ms 1372 KB Output is correct
4 Correct 3 ms 1116 KB Output is correct
5 Correct 6 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 6360 KB Output is correct
2 Correct 13 ms 9428 KB Output is correct
3 Correct 12 ms 9428 KB Output is correct
4 Correct 12 ms 6548 KB Output is correct
5 Correct 17 ms 10052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 4 ms 1116 KB Output is correct
18 Correct 3 ms 1372 KB Output is correct
19 Correct 3 ms 1116 KB Output is correct
20 Correct 6 ms 1116 KB Output is correct
21 Correct 10 ms 6360 KB Output is correct
22 Correct 13 ms 9428 KB Output is correct
23 Correct 12 ms 9428 KB Output is correct
24 Correct 12 ms 6548 KB Output is correct
25 Correct 17 ms 10052 KB Output is correct
26 Correct 13 ms 3548 KB Output is correct
27 Correct 10 ms 4564 KB Output is correct
28 Correct 8 ms 3548 KB Output is correct
29 Correct 8 ms 3548 KB Output is correct
30 Correct 9 ms 4568 KB Output is correct