Submission #572696

# Submission time Handle Problem Language Result Execution time Memory
572696 2022-06-05T05:11:21 Z Devigo Collecting Mushrooms (NOI18_collectmushrooms) C++14
79 / 100
2000 ms 5460 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair

const int siz = 0;
const int mod = 0;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int r, c, d, k;
	cin >> r >> c >> d >> k;
	vector<string> v(r);
	for(int i=0; i<r; i++) {
		cin >> v[i];
	}
	if(r == 1) {
		vector<int> ps(c+1,0);
		for(int i=1; i<=c; i++) {
			ps[i] = ps[i-1];
			if(v[0][i-1] == 'S') ps[i]++;
		}
		//for(int i=0; i<=c; i++) {
		//	cout << ps[i] << " ";
		//}
		cout << endl;
		int cnt = 0;
		for(int i=0; i<c; i++) {
			if(v[0][i] == 'M') {
				int mi = max(1,(i+1-d));
				int ma = min(c,(i+1+d));
				int cn = (ps[i]-ps[mi-1]) + (ps[ma]-ps[i]);
				if(cn >= k) cnt++;
			}
		}
		cout << cnt << "\n"; return 0;
	}
	//for(int i=0; i<r; i++) {
	//	for(int j=0; j<c; j++) {
	//		cout << v[i][j] << " ";
	//	}
	//	cout << "\n";
	//}
	vector<vector<int>> cnt(r,vector<int>(c,0));
	for(int i=0; i<r; i++) {
		for(int j=0; j<c; j++) {
			if(v[i][j] == 'S') {
				int x,y,z,e; //cout << "c\n";
				x = max(0,i-d);
				y = max(0,j-d);
				z = min(r-1,i+d);
				e = min(c-1,j+d);
				for(int sp=x; sp<=z; sp++) {
					for(int ep=y; ep<=e; ep++) {
						cnt[sp][ep]++;
					}
				}
			}
		}
	}
	//for(int i=0; i<r; i++) {
	//	for(int j=0; j<c; j++) {
	//		cout << cnt[i][j] << " ";
	//	}
	//	cout << endl;
	//}
	int cn = 0;
	for(int i=0; i<r; i++) {
		for(int j=0; j<c; j++) {
			if(v[i][j] == 'M' && cnt[i][j] >= k) cn++;
		}
	}
	cout << cn << "\n";
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 16 ms 368 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 16 ms 368 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 39 ms 360 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1236 KB Output is correct
2 Correct 46 ms 1236 KB Output is correct
3 Correct 10 ms 1492 KB Output is correct
4 Correct 51 ms 1364 KB Output is correct
5 Correct 3 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2792 KB Output is correct
2 Correct 6 ms 3336 KB Output is correct
3 Correct 6 ms 3356 KB Output is correct
4 Correct 7 ms 3360 KB Output is correct
5 Correct 7 ms 3272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 16 ms 368 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 39 ms 360 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 7 ms 1236 KB Output is correct
17 Correct 46 ms 1236 KB Output is correct
18 Correct 10 ms 1492 KB Output is correct
19 Correct 51 ms 1364 KB Output is correct
20 Correct 3 ms 1364 KB Output is correct
21 Correct 6 ms 2792 KB Output is correct
22 Correct 6 ms 3336 KB Output is correct
23 Correct 6 ms 3356 KB Output is correct
24 Correct 7 ms 3360 KB Output is correct
25 Correct 7 ms 3272 KB Output is correct
26 Execution timed out 2066 ms 5460 KB Time limit exceeded
27 Halted 0 ms 0 KB -