Submission #538914

#TimeUsernameProblemLanguageResultExecution timeMemory
538914ac2huCollecting Mushrooms (NOI18_collectmushrooms)C++14
100 / 100
13 ms5460 KiB
#include <bits/stdc++.h> #ifdef DEBUG #include "../templates/debug.h" #else #define deb(x...) #endif using namespace std; signed main() { iostream::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr); int r,c,d,k;cin >> r >> c >> d >> k; vector<vector<int>> pref(r,vector<int>(c,0)); vector<string> temp(r); for(auto &e : temp)cin >> e; for(int i = 0;i<r;i++){ for(int j = 0;j<c;j++){ if(temp[i][j] == 'S'){ deb(i,j); pref[max(i - d,0)][max(j - d,0)]++; if(j + d + 1 < c){ pref[max(i - d,0)][min(j + d + 1, c - 1)]--; } if(i + d + 1 < r){ pref[min(i + d + 1,r - 1)][max(j - d, 0)]--; } if(i + d + 1 < r && j + d + 1 < c){ pref[min(i + d + 1, r- 1)][min(j + d + 1,c - 1)]++; } } } } for(int i = 1;i<r;i++) pref[i][0] += pref[i - 1][0]; for(int j = 1;j<c;j++) pref[0][j] += pref[0][j - 1]; for(int i = 1;i<r;i++){ for(int j = 1;j<c;j++){ // if(i == ) pref[i][j] += pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1]; } } // for(int i =0 ;i<r;i++){ // for(int j = 0;j<c;j++) // cout << pref[i][j] << " "; // cout << "\n"; // } // cout << "---------\n"; int cc = 0; for(int i = 0;i<r;i++){ for(int j = 0;j<c;j++){ if(temp[i][j] == 'M' && pref[i][j] >= k){ cc++; } } } cout << cc << "\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...