제출 #925569

#제출 시각아이디문제언어결과실행 시간메모리
925569vjudge1Collecting Mushrooms (NOI18_collectmushrooms)C++17
100 / 100
13 ms9260 KiB
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

#define int long long
#define ff first
#define ss second
#define pb push_back
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define no1 cout<<"-1\n"

using namespace std;

const int N = 2e5+10;
const int M = 2e5+100;
const int INF = 1e18;
const int mod = 998244353;
  
// int binpow (int a, int n) {
// 	if (n == 0)
// 		return 1;
// 	if (n % 2 == 1)
// 		return (binpow (a, n-1) * a)%mod;
// 	else {
// 		int b = binpow (a, n/2) % mod;
// 		return (b * b)%mod;
// 	}
// }

int n,m,d,k;

void solve(){
    cin>>n>>m>>d>>k;
    char a[n+1][m+1];
    int b[n+1][m+1];
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            b[i][j] = 0;
        }
    }
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            cin>>a[i][j];
            if(a[i][j] == 'S'){
                int x1 = max(1ll,i-d);
                int y1 = max(1ll,j-d);
                int x2 = min(n,i+d);
                int y2 = min(m,j+d);
                b[x1][y1]++;
                if(x2 + 1 <= n){
                    b[x2 + 1][y1]--;
                }
                if(y2 + 1 <= m){
                    b[x1][y2 + 1]--;
                }
                if(x2 + 1 <= n && y2 + 1 <= m){
                    b[x2 + 1][y2 + 1]++;
                }
            }
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(i > 1){
                b[i][j] += b[i - 1][j];
            }
            if(j > 1){
                b[i][j] += b[i][j - 1];
            }
            if(i > 1 && j > 1){
                b[i][j] -= b[i - 1][j - 1];
            }
        }
    }
    int ans = 0;
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            if(a[i][j] == 'M' && b[i][j]>=k) ans++;
        }
    }
    cout<<ans<<'\n';
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    // cout.tie(nullptr);
    int t = 1; 
    // cin>>t;
    //   cout<<"";
    for(int i = 1;i<=t;i++){
        solve();
        // cout<<'\n';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...