답안 #854562

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854562 2023-09-28T05:02:06 Z MilosMilutinovic Collecting Mushrooms (NOI18_collectmushrooms) C++14
100 / 100
37 ms 50684 KB
#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int r,c,d,k,fenw[500005],cnt[500005];
char s[500005];
vector<pii> a,b;
vector<int> qs[500005][3];

void update(int p,int v){
	for(;p<500005;p+=p&-p) fenw[p]+=v;
}
int query(int p){
	int res=0;
	for(;p>0;p-=p&-p) res+=fenw[p];
	return res;
}
int query(int l,int r){
	return query(r)-query(l-1);
}

int main(){
	r=readint(); c=readint(); d=readint(); k=readint();
	for(int i=1;i<=r;i++){
		scanf("%s",s+1);
		for(int j=1;j<=c;j++){
			if(s[j]=='M') a.pb(mp(i,j));
			if(s[j]=='S') b.pb(mp(i,j));
		}
	}
	for(int i=0;i<(int)a.size();i++){
		qs[max(1,a[i].fi-d)][0].pb(i);
		qs[min(r,a[i].fi+d)][1].pb(i);
	}
	for(int i=0;i<(int)b.size();i++){
		qs[b[i].fi][2].pb(i);
	}
	for(int i=1;i<=r;i++){
		for(int j:qs[i][0]) cnt[j]-=query(max(1,a[j].se-d),min(c,a[j].se+d));
		for(int j:qs[i][2]) update(b[j].se,+1);
		for(int j:qs[i][1]) cnt[j]+=query(max(1,a[j].se-d),min(c,a[j].se+d));
	}
	int ans=0;
	for(int i=0;i<(int)a.size();i++) if(cnt[i]>=k) ans++;
	printf("%d\n",ans);
	return 0;
}

Compilation message

mushrooms.cpp: In function 'int main()':
mushrooms.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   scanf("%s",s+1);
      |   ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 37468 KB Output is correct
2 Correct 8 ms 37720 KB Output is correct
3 Correct 8 ms 37468 KB Output is correct
4 Correct 8 ms 37468 KB Output is correct
5 Correct 7 ms 37556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 37468 KB Output is correct
2 Correct 8 ms 37720 KB Output is correct
3 Correct 8 ms 37468 KB Output is correct
4 Correct 8 ms 37468 KB Output is correct
5 Correct 7 ms 37556 KB Output is correct
6 Correct 7 ms 37468 KB Output is correct
7 Correct 8 ms 37468 KB Output is correct
8 Correct 8 ms 37732 KB Output is correct
9 Correct 8 ms 37468 KB Output is correct
10 Correct 7 ms 37468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 37468 KB Output is correct
2 Correct 8 ms 37680 KB Output is correct
3 Correct 8 ms 37808 KB Output is correct
4 Correct 8 ms 37624 KB Output is correct
5 Correct 8 ms 37468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 37760 KB Output is correct
2 Correct 9 ms 37724 KB Output is correct
3 Correct 9 ms 37976 KB Output is correct
4 Correct 8 ms 37700 KB Output is correct
5 Correct 9 ms 37724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 44484 KB Output is correct
2 Correct 37 ms 49864 KB Output is correct
3 Correct 28 ms 49344 KB Output is correct
4 Correct 34 ms 47176 KB Output is correct
5 Correct 33 ms 50684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 37468 KB Output is correct
2 Correct 8 ms 37720 KB Output is correct
3 Correct 8 ms 37468 KB Output is correct
4 Correct 8 ms 37468 KB Output is correct
5 Correct 7 ms 37556 KB Output is correct
6 Correct 7 ms 37468 KB Output is correct
7 Correct 8 ms 37468 KB Output is correct
8 Correct 8 ms 37732 KB Output is correct
9 Correct 8 ms 37468 KB Output is correct
10 Correct 7 ms 37468 KB Output is correct
11 Correct 8 ms 37468 KB Output is correct
12 Correct 8 ms 37680 KB Output is correct
13 Correct 8 ms 37808 KB Output is correct
14 Correct 8 ms 37624 KB Output is correct
15 Correct 8 ms 37468 KB Output is correct
16 Correct 8 ms 37760 KB Output is correct
17 Correct 9 ms 37724 KB Output is correct
18 Correct 9 ms 37976 KB Output is correct
19 Correct 8 ms 37700 KB Output is correct
20 Correct 9 ms 37724 KB Output is correct
21 Correct 22 ms 44484 KB Output is correct
22 Correct 37 ms 49864 KB Output is correct
23 Correct 28 ms 49344 KB Output is correct
24 Correct 34 ms 47176 KB Output is correct
25 Correct 33 ms 50684 KB Output is correct
26 Correct 21 ms 41672 KB Output is correct
27 Correct 21 ms 43468 KB Output is correct
28 Correct 22 ms 42064 KB Output is correct
29 Correct 17 ms 40520 KB Output is correct
30 Correct 23 ms 41932 KB Output is correct