Submission #321032

# Submission time Handle Problem Language Result Execution time Memory
321032 2020-11-10T17:07:16 Z wind_reaper Collecting Mushrooms (NOI18_collectmushrooms) C++17
38 / 100
38 ms 10952 KB
// #define _GLIBCXX_DEBUG
// #pragma GCC optimize "trapv"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

using namespace std;
using namespace __gnu_pbds;

#define pb push_back 
#define f first
#define s second
#define min3(a, b, c) min(min(a, b), c)
#define max3(a, b, c) max(max(a, b), c)
#define all(v) v.begin(), v.end()

typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

template <class T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

const int INF = 1e9;
// const ll INF = 1e18;
const ll mod = 1000000007;
// const ll mod = 998244353;

void solve(int tc){
	/*int r, c, d, k;
	cin >> r >> c >> d >> k;

	vvi rang(r, vi(c));
	vpi mush;
	for(int i = 0; i < r; i++){
		for(int j = 0; j < c; j++){
			char rx;
			cin >> rx;
			if(rx == '.') continue;
			else if(rx == 'M'){
				mush.pb({i, j});
			}
			else{
				for(int x = max(i - d, 0); x < min(i+d+1, r); x++){
					for(int y = max(j - d, 0); y < min(j+d+1, c); y++) 
						rang[x][y]++;
				}
			}
		}
	}*/
	/*int ans = 0;

	for(int i = 0; i < mush.size(); i++)
		if(rang[mush[i].f][mush[i].s] >= k)
			ans++;

	cout << ans << '\n';*/

	int r, c, d, k;
	cin >> r >> c >> d >> k;

	vvi rang(r+1, vi(c+1));
	vpi mush;
	for(int i = 0; i < r; i++){
		for(int j = 0; j < c; j++){
			char rx;
			cin >> rx;
			if(rx == '.') continue;
			else if(rx == 'M'){
				mush.pb({i, j});
			}
			else{
				rang[max(0, i-d)][max(0, j-d)]++;
				rang[max(0, i-d)][min(j+d+1, c)]--;
				rang[min(i+d+1, r)][max(0, j-d)]--;
				rang[min(i+d+1, r)][min(j+d+1, c)]++;
			}
		}
	}
	for(int i = 1; i < r; i++)
		rang[i][0] += rang[i-1][0];
	for(int i = 1; i < c; i++)
		rang[0][i] += rang[0][i-1];
	for(int i = 1; i <= r; i++)
		for(int j = 1; j <= c; j++)
			rang[i][j] = rang[i][j-1]+rang[i-1][j]-rang[i-1][j-1];

	/*for(int i = 0; i < r; i++){
		for(int j = 0; j < c; j++){
			cout << rang[i][j] << ' ';
		}
		cout << '\n';
	}*/
	int ans = 0;

	for(int i = 0; i < mush.size(); i++)
		if(rang[mush[i].f][mush[i].s] >= k)
			ans++;

	cout << ans << '\n';
}

int main(){
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	
	int tc = 1;
	// cin >> tc;
	for (int t = 0; t < tc; t++) solve(t);

	return 0;
}

Compilation message

mushrooms.cpp: In function 'void solve(int)':
mushrooms.cpp:107:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |  for(int i = 0; i < mush.size(); i++)
      |                 ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1388 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 8264 KB Output is correct
2 Correct 28 ms 10952 KB Output is correct
3 Correct 27 ms 10952 KB Output is correct
4 Correct 38 ms 8388 KB Output is correct
5 Correct 31 ms 10952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Incorrect 1 ms 364 KB Output isn't correct
12 Halted 0 ms 0 KB -