Submission #925616

# Submission time Handle Problem Language Result Execution time Memory
925616 2024-02-12T06:20:13 Z vjudge1 Collecting Mushrooms (NOI18_collectmushrooms) C++17
0 / 100
2000 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
#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

signed main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
      #ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.out", "w", stdout);
      #endif

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

	if( n == 1 ) {
		int msh = 0;
		int spr = 0;

		vector<int> cnt(m+1, 0);
		char c[m+1];
		for( int i = 1; i <= m; i++ ) {
			cin >> c[i];
			if( c[i] == 'S') {
				cnt[max(i-d,1)]++;
				if( i+d+1 <= m ) cnt[i+d+1]--;
			}
		}
		int ans = 0;
		for( int i = 1; i <= m; i++ ) {
			spr += cnt[i];
			if( c[i] == 'M') {
				if( spr >= k ) ans++;
			}
		}
		cout << ans;

		return 0;
	} else {
		vector<pii> msh;
		vector<pii> spr;
		for( int i = 1; i <= n; i++ ) {
			for( int j = 1; j <= m; j++ ) {
				char c; cin >> c;
				if( c == 'M') msh.emb(i,j);
				if( c == '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:26:7: warning: unused variable 'msh' [-Wunused-variable]
   26 |   int msh = 0;
      |       ^~~
mushrooms.cpp:61:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   for( int i = 0; i < msh.size(); i++ ) {
      |                   ~~^~~~~~~~~~~~
mushrooms.cpp:65: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]
   65 |     if( pos >= 0 && pos < spr.size() ) {
      |                     ~~~~^~~~~~~~~~~~
mushrooms.cpp:67:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |      for( int j = pos; j < spr.size(); j++ ) {
      |                        ~~^~~~~~~~~~~~
mushrooms.cpp:18:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 | freopen("input.txt", "r", stdin);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
mushrooms.cpp:19:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 | freopen("output.out", "w", stdout);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2039 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -