Submission #391996

#TimeUsernameProblemLanguageResultExecution timeMemory
391996sumit_kk10Collecting Mushrooms (NOI18_collectmushrooms)C++14
100 / 100
15 ms5196 KiB
#include <bits/stdc++.h> #define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL) #define ll long long int #define ld long double using namespace std; const int N = 1e6 + 5; const int MOD = 1e9 + 7; int main(){ fast; int n, m, d, k; cin >> n >> m >> d >> k; char a[n + 1][m + 1]; int pre_sum[n + 1][m + 1]; memset(pre_sum, 0, sizeof pre_sum); for(int i = 1; i <= n; ++i){ for(int j = 1; j <= m; ++j){ cin >> a[i][j]; pre_sum[i][j] = pre_sum[i - 1][j] + pre_sum[i][j - 1] - pre_sum[i - 1][j - 1]; if(a[i][j] == 'S') ++pre_sum[i][j]; } } int ans = 0; for(int i = 1; i <= n; ++i){ for(int j = 1; j <= m; ++j){ if(a[i][j] == 'M'){ int x = max(1, j - d), y = min(m, j + d), x1 = max(1, i - d), y1 = min(n, i + d); if((pre_sum[y1][y] - pre_sum[x1 - 1][y] - pre_sum[y1][x - 1] + pre_sum[x1 - 1][x - 1]) >= k) ++ans; } } } cout << ans << '\n'; return 0; }
#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...