Submission #921513

#TimeUsernameProblemLanguageResultExecution timeMemory
921513BzslayedCollecting Mushrooms (NOI18_collectmushrooms)C++17
100 / 100
11 ms5836 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define pff pair<float, float> #define coutpair(p) cout << p.first << " " << p.second << "\n" typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll r, c, d, k; cin >> r >> c >> d >> k; char arr[r+1][c+1]; int pre[r+1][c+1]; memset(pre, 0, sizeof(pre)); for (int i=1; i<=r; i++) { for (int j=1; j<=c; j++) { cin >> arr[i][j]; if (arr[i][j] == 'S') pre[i][j] = 1; else pre[i][j] = 0; pre[i][j] = pre[i][j] + pre[i - 1][j] + pre[i][j - 1] - pre[i - 1][j - 1]; } } ll ans = 0; for (int i=1; i<=r; i++) { for (int j=1; j<=c; j++) { if (arr[i][j] == 'M') { int x1 = i - d; int y1 = j - d; int x2 = i + d; int y2 = j + d; if (x1 <= 0) x1 = 1; if (y1 <= 0) y1 = 1; if (x2 > r) x2 = r; if (y2 > c) y2 = c; if (pre[x2][y2] - pre[x1 - 1][y2] - pre[x2][y1 - 1] + pre[x1 - 1][y1 - 1] >= k) { ans = ans + 1; } } } } cout << ans; return 0; }
#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...