답안 #925579

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925579 2024-02-12T05:32:56 Z vjudge1 Collecting Mushrooms (NOI18_collectmushrooms) C++17
0 / 100
135 ms 262144 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>;

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;

	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;
		int pos = lower_bound(spr.begin(), spr.end(), make_pair(msh[i].F-d, msh[i].S-d)) - spr.begin();
		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:48: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]
   48 |  for( int i = 0; i < msh.size(); i++ ) {
      |                  ~~^~~~~~~~~~~~
mushrooms.cpp:52:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   for( int j = pos; j < spr.size(); j++ ) {
      |                     ~~^~~~~~~~~~~~
mushrooms.cpp:27:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 | freopen("input.txt", "r", stdin);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
mushrooms.cpp:28:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 | freopen("output.out", "w", stdout);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 135 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 135 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 132 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 122 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 125 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 135 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -