Submission #586477

#TimeUsernameProblemLanguageResultExecution timeMemory
586477M_WCollecting Mushrooms (NOI18_collectmushrooms)C++17
38 / 100
9 ms7260 KiB
#include <bits/stdc++.h> #define ii pair<int, int> using namespace std; vector<vector<int>> v; int ans = 0; queue<ii> q; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int N, M, D, K; cin >> N >> M >> D >> K; int rd = D * 2 + 1; for(int i = 0; i < N; i++){ string line; cin >> line; vector<int> tmp; for(int j = 0; j < M; j++){ int qsl = j == 0 ? 0 : tmp[j - 1]; int qsu = i == 0 ? 0 : v[i - 1][j]; int qslu = (i == 0 || j == 0) ? 0 : v[i - 1][j - 1]; tmp.push_back(qsl + qsu - qslu + (line[j] == 'S' ? 1 : 0)); if(line[j] == 'M') q.push({i + D, j + D}); while(!q.empty() && min(q.front().first, N - 1) == i && min(q.front().second, M - 1) == j){ auto [ni, nj] = q.front(); int qsu2 = ni - rd < 0 ? 0 : v[ni - rd][j]; int qsl2 = nj - rd < 0 ? 0 : tmp[nj - rd]; int qslu2 = (ni - rd < 0 || nj - rd < 0) ? 0 : v[ni - rd][nj - rd]; if(tmp[j] - qsl2 - qsu2 + qslu2 >= K) ans++; // printf(">> %d %d : %d\n", i - rd, j - rd, tmp[j] - qsl2 - qsu2 + qslu2 >= K); q.pop(); } } v.push_back(tmp); } 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...