Submission #925584

# Submission time Handle Problem Language Result Execution time Memory
925584 2024-02-12T05:36:17 Z vjudge1 Collecting Mushrooms (NOI18_collectmushrooms) C++17
60 / 100
2000 ms 4296 KB
#include <bits/stdc++.h>
using namespace std;
#define emb emplace_back
#define pii pair<int,int>
#define F first
#define S second

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;

	char c[n+1][m+1];
	
	vector<pii> msh;
	vector<pii> spr;
	for( int i = 1; i <= n; i++ ) {
		for( int j = 1; j <= m; j++ ) {
			cin >> c[i][j];
			if( c[i][j] == 'M') msh.emb(i,j);
			if( c[i][j] == 'S') spr.emb(i,j);
		}
	}
	sort(spr.begin(), spr.end());

	int ans = 0;
	for( int i = 0; i < msh.size(); i++ ) {
		int cnt = 0;
		if( spr.size() > 0 ) {
			int pos = lower_bound(spr.begin(), spr.end(), make_pair(msh[i].F-d, msh[i].S-d)) - spr.begin();
			if( pos >= 0 && pos < spr.size() ) {
				if( (spr[pos].F - msh[i].F) > d ) pos++;
				for( int j = pos; j < spr.size(); j++ ) {
					if( abs(msh[i].F - spr[j].F) > d ) break;
					if( abs(msh[i].S - spr[j].S) <= d ) cnt++;
					if( cnt >= k ) break;
				}
				if( cnt >= k ) {
					ans++;
				}
			}
		}
	}
	cout << ans;

return 0;
}

Compilation message

mushrooms.cpp: In function 'int main()':
mushrooms.cpp:31:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |  for( int i = 0; i < msh.size(); i++ ) {
      |                  ~~^~~~~~~~~~~~
mushrooms.cpp:35:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |    if( pos >= 0 && pos < spr.size() ) {
      |                    ~~~~^~~~~~~~~~~~
mushrooms.cpp:37:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for( int j = pos; j < spr.size(); j++ ) {
      |                       ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 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 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 11 ms 580 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 2 ms 604 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 3 ms 712 KB Output is correct
4 Correct 3 ms 600 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2100 ms 4296 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 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 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 11 ms 580 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 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 2 ms 604 KB Output is correct
17 Correct 2 ms 604 KB Output is correct
18 Correct 3 ms 712 KB Output is correct
19 Correct 3 ms 600 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Execution timed out 2100 ms 4296 KB Time limit exceeded
22 Halted 0 ms 0 KB -