Submission #1151475

#TimeUsernameProblemLanguageResultExecution timeMemory
1151475tntCollecting Mushrooms (NOI18_collectmushrooms)C++20
79 / 100
42 ms5316 KiB
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")

#define pb push_back                    
#define ll long long
#define all(v) v.begin(),v.end()

int mod = 1e8;
const int N = 1e6;
const int inf = 2e9;
 
int w[600][600],w1[2][N + 100];
signed main(){
    //freopen("shuffle.in", "r", stdin);
    //freopen("shuffle.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,m,d,k;
    cin >> n >> m >> d >> k;
    char a[n + 1][m + 1];
    vector <pair <int,int>> v;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> a[i][j];
            if(a[i][j] == 'S') v.pb({i,j});
        }   
    }
    if(n <= 500 && m <= 500){
        int ans = 0; 
        for(auto to : v){
            int x = to.first,y = to.second;
            for(int i = max(1,x - d); i <= min(n,x + d); i++){
                for(int j = max(1,y - d); j <= min(m,y + d); j++){
                    w[i][j]++;
                }
            }
        }
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                if(a[i][j] == 'M' && w[i][j] >= k) ans++;
            }
        }
        cout << ans;
    }
    else{
        int ans = 0;
        for(int j = 1; j <= m; j++){
            if(a[1][j] == 'S'){
                w1[1][max(1,j - d)]++,w1[1][min(m,j + d) + 1]--;
            }
        }
        for(int j = 1; j <= m; j++){
            w1[1][j] += w1[1][j - 1];
        }
        for(int j = 1; j <= m; j++){
            if(a[1][j] == 'M' && w1[1][j] >= k) ans++;
        }
        cout << ans;
    }
    
}
#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...