Submission #1060428

#TimeUsernameProblemLanguageResultExecution timeMemory
1060428KazooCollecting Mushrooms (NOI18_collectmushrooms)C++17
0 / 100
128 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int maxR = 5e5+5; int r, c, d, k; string garden[maxR]; int main(){ bool watered[maxR][maxR]; memset(watered, false, sizeof(watered)); cin >> r >> c >> d >> k; for(int i = 0; i<r; i++){ cin >> garden[i]; } vector<vector<int>> kena; for(int i = 0; i<r; i++){ vector<int> ps; for(int j = 0; j<c; j++){ ps.push_back(0); } kena.push_back(ps); } for(int i = 0; i<r; i++){ for(int j = 0; j<c; j++){ if(garden[i][j]=='S') { // atas kiri [i-d][j-d] // bawah kanan [i+d][j+d] // atas kanan [i-d][j+d] // bawah kiri [i+d][j-d] int atas = max(i-d, 0); int kiri = max(j-d, 0); kena[atas][kiri]++; int kanan = -1, bawah = -1; if(i+d+1<=r-1) bawah = i+d+1; if(j+d+1<=c-1) kanan = j+d+1; if(kanan!=-1) kena[atas][kanan]--; if(bawah!=-1) kena[bawah][kiri]--; if(kanan!=-1 && bawah!=-1) kena[kanan][bawah]++; } } } ll ans = 0; for(int i = 0; i<r; i++){ for(int j = 0; j<c; j++){ if(i!=0) kena[i][j] += kena[i-1][j]; if(j!=0) kena[i][j] += kena[i][j-1]; if(i!=0 && j!=0) kena[i][j] -= kena[i-1][j-1]; if(garden[i][j]=='M' && kena[i][j] >= k) ans++; } // cout << endl; } cout << ans << endl; }
#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...