Submission #754704

#TimeUsernameProblemLanguageResultExecution timeMemory
754704UnforgettableplCollecting Mushrooms (NOI18_collectmushrooms)C++17
100 / 100
22 ms13128 KiB
/* ID: samikgo1 TASK: LANG: C++ */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; #define all(x) x.begin(),x.end() #define allr(x) x.rbegin(),x.rend() #define f first #define s second //#define x first //#define y second const int INF = INT32_MAX; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); // freopen("haybales.in","r",stdin); // freopen("haybales.out","w",stdout); ll r,c,d,k; cin >> r >> c >> d >> k; char grid[r+1][c+1]; vector<vector<ll>> prefix(r+1,vector<ll>(c+1)); for (int i = 1; i <= r; i++) { for (int j = 1; j <= c; j++) { prefix[i][j] = prefix[i-1][j] + prefix[i][j-1] - prefix[i-1][j-1]; cin>>grid[i][j]; if(grid[i][j]=='S')prefix[i][j]++; } } ll ans = 0; for (int i = 1; i <= r; i++) { for (int j = 1; j <= c; j++) { if(grid[i][j]!='M')continue; ll pre = prefix[min(i+d,r)][min(j+d,c)]+prefix[max(i-d-1,(ll)0)][max(j-d-1,(ll)0)] - prefix[max(i-d-1,(ll)0)][min(j+d,c)] - prefix[min(i+d,r)][max(j-d-1,(ll)0)]; if(pre>=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...