Submission #1280601

#TimeUsernameProblemLanguageResultExecution timeMemory
1280601alialiCollecting Mushrooms (NOI18_collectmushrooms)C++20
79 / 100
2094 ms15084 KiB
#include <bits/stdc++.h> #define int long long using namespace std; #define ar array #define boost ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); const int N = 1e6 + 12, INF = 1e18 + 7, mod = 1e9 + 7; signed main () { boost int r, c, d, k; cin >> r >> c >> d >> k; char arr[r + 1][c + 1]; vector<pair<int, int>>v, v2; for(int i = 1; i <= r; ++i){ for(int j = 1; j <= c; ++j){ cin >> arr[i][j]; if(arr[i][j] == 'M'){ v.push_back({i, j}); } if(arr[i][j] == 'S'){ v2.push_back({i, j}); } } } if(r != 1){ int cnt = 0; for(auto [x, y] : v){ int cn = 0; for(auto [x2, y2]: v2){ int hm = max(abs(x2 - x), abs(y2 - y)); if(hm <= d){ cn += 1; } if(cn >= k){ break; } } if(cn >= k){ cnt += 1; } } cout << cnt << '\n'; } else { int pref[c + 1]; pref[0] = 0; for(int i = 1; i <= r; ++i){ for(int j = 1; j <= c; ++j){ pref[j] = pref[j - 1]; if(arr[i][j] == 'S'){ pref[j] += 1; } } } int cnt2 = 0; for(auto [x, y] : v){ int sc = min(c, y + d); int cnt = 0; cnt += (pref[sc] - pref[y]); sc = max((int)1, y - d); cnt += (pref[y] - pref[sc]); if(arr[x][sc] == 'S'){ cnt += 1; } if(cnt >= k){ cnt2 += 1; } } cout << cnt2 << '\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...