Submission #205044

#TimeUsernameProblemLanguageResultExecution timeMemory
205044Haunted_CppCollecting Mushrooms (NOI18_collectmushrooms)C++17
100 / 100
20 ms4472 KiB
#include <iostream> #include <vector> #include <cstring> using namespace std; #define FOR(i, a, b) for (int i = a; i < (int) b; i++) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for (int i = a; i >= (int) b; i--) #define R0F(i, a) ROF(i, a, 0) #define GO(i, a) for (auto i : a) #define f first #define s second #define eb emplace_back #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef vector<vi> vvi; typedef vector<vpii> vvpii; typedef long long i64; typedef vector<i64> vi64; const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1}; const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1}; const int ms[] = {+31, +29, +31, 30, +31, +30, +31, +31, +30, +31, +30, +31}; vvi dp; vector< vector<char> > g; int main () { ios::sync_with_stdio(0); cin.tie(0); int r, c, d, k; cin >> r >> c >> d >> k; g.resize(r); dp.resize(r); F0R (i, r) { g[i].resize(c); dp[i].resize(c); } F0R (i, r) { F0R (j, c) { cin >> g[i][j]; } } dp[0][0] = (g[0][0] == 'S'); FOR (i, 1, r) { dp[i][0] = dp[i - 1][0] + (g[i][0] == 'S'); } FOR (i, 1, c) { dp[0][i] = dp[0][i - 1] + (g[0][i] == 'S'); } FOR (i, 1, r) { FOR (j, 1, c) { dp[i][j] += dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + (g[i][j] == 'S'); } } int tot = 0; F0R (i, r) { F0R (j, c) { if (g[i][j] == 'M') { int linha = min (r - 1, i + d); int coluna = min (c - 1, j + d); int cnt = dp[linha][coluna] - (i - d - 1 >= 0 ? dp[i - d - 1][coluna] : 0) - (j - d - 1 >= 0 ? dp[linha][j - d - 1] : 0) + (i - d - 1 >= 0 && j - d - 1 >= 0 ? dp[i - d - 1][j - d - 1] : 0); tot += (cnt >= k); } } } cout << tot << '\n'; 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...