답안 #146965

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
146965 2019-08-27T01:36:07 Z gs14004 Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
34 ms 20368 KB
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int MAXN = 500005;

int n, m, d, k;
string s[MAXN];
char buf[MAXN];
vector<vector<int>> dx;

void add(int sx, int ex, int sy, int ey){
	sx = max(sx, 0); ex = min(ex, n - 1);
	sy = max(sy, 0); ey = min(ey, m - 1);
	if(sx <= ex && sy <= ey){
		dx[sx][sy]++;
		if(ey + 1 < m) dx[sx][ey+1]--;
		if(ex + 1 < n) dx[ex+1][sy]--;
		if(ex + 1 < n && ey + 1 < m) dx[ex+1][ey+1]++;
	}
}

int main(){
	scanf("%d %d %d %d",&n,&m,&d,&k);
	dx.resize(n);
	for(int i=0; i<n; i++){
		scanf("%s", buf);
		s[i] = buf;
		dx[i].resize(m);
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(s[i][j] == 'S'){
				add(i - d, i + d, j - d, j + d);
			}
		}
	}
	int ret = 0;
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(i) dx[i][j] += dx[i-1][j];
			if(j) dx[i][j] += dx[i][j-1];
			if(i&&j) dx[i][j] -= dx[i-1][j-1];
			if(s[i][j] == 'M' && dx[i][j] >= k) ret++;
		}
	}
	cout << ret << endl;
}

Compilation message

mushrooms.cpp: In function 'int main()':
mushrooms.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d %d",&n,&m,&d,&k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
mushrooms.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", buf);
   ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 15992 KB Output is correct
2 Correct 18 ms 16120 KB Output is correct
3 Correct 18 ms 15864 KB Output is correct
4 Correct 15 ms 15992 KB Output is correct
5 Correct 19 ms 15992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 15992 KB Output is correct
2 Correct 18 ms 16120 KB Output is correct
3 Correct 18 ms 15864 KB Output is correct
4 Correct 15 ms 15992 KB Output is correct
5 Correct 19 ms 15992 KB Output is correct
6 Correct 15 ms 15992 KB Output is correct
7 Correct 15 ms 15992 KB Output is correct
8 Correct 16 ms 15992 KB Output is correct
9 Correct 15 ms 15992 KB Output is correct
10 Correct 18 ms 15996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 15992 KB Output is correct
2 Correct 16 ms 15992 KB Output is correct
3 Correct 15 ms 15992 KB Output is correct
4 Correct 15 ms 15992 KB Output is correct
5 Correct 19 ms 15992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 17072 KB Output is correct
2 Correct 19 ms 17272 KB Output is correct
3 Correct 21 ms 17628 KB Output is correct
4 Correct 19 ms 17144 KB Output is correct
5 Correct 19 ms 17272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 19448 KB Output is correct
2 Correct 23 ms 19460 KB Output is correct
3 Correct 23 ms 19448 KB Output is correct
4 Correct 27 ms 19448 KB Output is correct
5 Correct 29 ms 19448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 15992 KB Output is correct
2 Correct 18 ms 16120 KB Output is correct
3 Correct 18 ms 15864 KB Output is correct
4 Correct 15 ms 15992 KB Output is correct
5 Correct 19 ms 15992 KB Output is correct
6 Correct 15 ms 15992 KB Output is correct
7 Correct 15 ms 15992 KB Output is correct
8 Correct 16 ms 15992 KB Output is correct
9 Correct 15 ms 15992 KB Output is correct
10 Correct 18 ms 15996 KB Output is correct
11 Correct 15 ms 15992 KB Output is correct
12 Correct 16 ms 15992 KB Output is correct
13 Correct 15 ms 15992 KB Output is correct
14 Correct 15 ms 15992 KB Output is correct
15 Correct 19 ms 15992 KB Output is correct
16 Correct 19 ms 17072 KB Output is correct
17 Correct 19 ms 17272 KB Output is correct
18 Correct 21 ms 17628 KB Output is correct
19 Correct 19 ms 17144 KB Output is correct
20 Correct 19 ms 17272 KB Output is correct
21 Correct 25 ms 19448 KB Output is correct
22 Correct 23 ms 19460 KB Output is correct
23 Correct 23 ms 19448 KB Output is correct
24 Correct 27 ms 19448 KB Output is correct
25 Correct 29 ms 19448 KB Output is correct
26 Correct 34 ms 20368 KB Output is correct
27 Correct 30 ms 18936 KB Output is correct
28 Correct 28 ms 18808 KB Output is correct
29 Correct 26 ms 18936 KB Output is correct
30 Correct 31 ms 19832 KB Output is correct