답안 #961425

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
961425 2024-04-12T05:21:11 Z vjudge1 Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
30 ms 21276 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ent "\n"

const int maxn = 5e5 + 100;
const ll INF = (ll)1e18 + 100;
const int inf = 1e9 + 100;
const int MOD = 1e9 + 7;
const int maxl = 30;
const int P = 31;

int n, m, d, k;
vector<int> pref[maxn];

void test(){
	cin >> n >> m >> d >> k;
	pref[0] = vector<int>(m + 10, 0);
	vector<pii> v, ad;
	for(int i = 1; i <= n; i++){
		pref[i] = pref[i-1];
		for(int j = 1; j <= m; j++){
			char c; cin >> c;
			if(c == 'M') v.push_back({i, j});
			else if(c == 'S') ad.push_back({i, j});
		}
	}
	for(auto [i, j]: ad){
		int a = max(1, i - d);
		int x = min(n, i + d);
		int b = max(1, j - d);
		int y = min(m, j + d);
		pref[a][b]++;
		pref[a][y+1]--;
		if(x < n){
			pref[x+1][b]--;
			pref[x+1][y+1]++;
		}
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			pref[i][j] += pref[i-1][j];
		}
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			pref[i][j] += pref[i][j-1];
		}
	}
	int ans = 0;
	for(auto [i, j]: v){
		if(pref[i][j] >= k) ans++;
	}
	cout << ans << ent;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int t = 1; t = 1;
	while(t--) test();
	cout << ent;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12120 KB Output is correct
2 Correct 4 ms 12124 KB Output is correct
3 Correct 4 ms 12124 KB Output is correct
4 Correct 4 ms 12124 KB Output is correct
5 Correct 3 ms 12124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12120 KB Output is correct
2 Correct 4 ms 12124 KB Output is correct
3 Correct 4 ms 12124 KB Output is correct
4 Correct 4 ms 12124 KB Output is correct
5 Correct 3 ms 12124 KB Output is correct
6 Correct 4 ms 12124 KB Output is correct
7 Correct 3 ms 12120 KB Output is correct
8 Correct 3 ms 12124 KB Output is correct
9 Correct 3 ms 12124 KB Output is correct
10 Correct 3 ms 12124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12124 KB Output is correct
2 Correct 3 ms 12120 KB Output is correct
3 Correct 4 ms 12380 KB Output is correct
4 Correct 3 ms 12200 KB Output is correct
5 Correct 3 ms 12124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 13148 KB Output is correct
2 Correct 7 ms 13148 KB Output is correct
3 Correct 7 ms 13404 KB Output is correct
4 Correct 6 ms 13148 KB Output is correct
5 Correct 14 ms 13148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 19400 KB Output is correct
2 Correct 15 ms 21204 KB Output is correct
3 Correct 20 ms 20948 KB Output is correct
4 Correct 17 ms 20704 KB Output is correct
5 Correct 17 ms 21276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12120 KB Output is correct
2 Correct 4 ms 12124 KB Output is correct
3 Correct 4 ms 12124 KB Output is correct
4 Correct 4 ms 12124 KB Output is correct
5 Correct 3 ms 12124 KB Output is correct
6 Correct 4 ms 12124 KB Output is correct
7 Correct 3 ms 12120 KB Output is correct
8 Correct 3 ms 12124 KB Output is correct
9 Correct 3 ms 12124 KB Output is correct
10 Correct 3 ms 12124 KB Output is correct
11 Correct 4 ms 12124 KB Output is correct
12 Correct 3 ms 12120 KB Output is correct
13 Correct 4 ms 12380 KB Output is correct
14 Correct 3 ms 12200 KB Output is correct
15 Correct 3 ms 12124 KB Output is correct
16 Correct 7 ms 13148 KB Output is correct
17 Correct 7 ms 13148 KB Output is correct
18 Correct 7 ms 13404 KB Output is correct
19 Correct 6 ms 13148 KB Output is correct
20 Correct 14 ms 13148 KB Output is correct
21 Correct 15 ms 19400 KB Output is correct
22 Correct 15 ms 21204 KB Output is correct
23 Correct 20 ms 20948 KB Output is correct
24 Correct 17 ms 20704 KB Output is correct
25 Correct 17 ms 21276 KB Output is correct
26 Correct 30 ms 17516 KB Output is correct
27 Correct 14 ms 16652 KB Output is correct
28 Correct 18 ms 17388 KB Output is correct
29 Correct 14 ms 16084 KB Output is correct
30 Correct 15 ms 17488 KB Output is correct