Submission #94858

#TimeUsernameProblemLanguageResultExecution timeMemory
94858karmaCollecting Mushrooms (NOI18_collectmushrooms)C++11
100 / 100
23 ms14200 KiB
#include<bits/stdc++.h> #define For(i, a, b) for(int i = a, _b = b; i <= _b; ++i) #define Ford(i, a, b) for(int i = a, _b = b; i >= _b; --i) #define FileName "test" #define ll long long #define ld long double #define ull unsigned long long #define Print(x) cerr << #x << "is " << x << '\n'; #define pb push_back #define X first #define Y second //#define Karma using namespace std; template<typename T> inline void Cin(T &x) { char c; T sign = 1; x = 0; for (c = getchar(); c < '0' || c > '9'; c = getchar()) if (c == '-') sign = -1; for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0'; x *= sign; } template <typename T> inline void Out(T x) {if(x > 9) Out(x / 10); putchar(x % 10 + '0');} template <typename T> inline void Cout(T x, char c) {if(x < 0) putchar('-'); x = abs(x); Out(x); putchar(c);} template <typename T, typename... Args> inline void Cin(T& a, Args&... args) {Cin(a);Cin(args...);} template <typename T, typename... Args> inline void Cout(T a, char c, Args... args) {Cout(a, c);Cout(args...);} typedef pair<int, int> pii; typedef pair<ll, int> plli; vector<vector<ll>> s; int r, c, d, k, res; vector<vector<char>> a; void Update(int x, int y, int u, int v) { ++s[x][y], ++s[u + 1][v + 1], --s[x][v + 1], --s[u + 1][y]; } void Enter() { cin >> r >> c >> d >> k; a.resize(r + 2), s.resize(r + 2); for(int i = 0; i <= r + 1; ++i) a[i].resize(c + 2), s[i].resize(c + 2); for(int i = 1; i <= r; ++i) { for(int j = 1; j <= c; ++j) { cin >> a[i][j]; if(a[i][j] == 'S') Update(max(i - d, 1), max(j - d, 1), min(i + d, r), min(j + d, c)); } } } void Solve() { for(int i = 1; i <= r; ++i) { for(int j = 1; j <= c; ++j) { s[i][j] += (s[i][j - 1] + s[i - 1][j] - s[i - 1][j - 1]); if(s[i][j] >= k && a[i][j] == 'M') ++res; } } cout << res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef Karma freopen(FileName".inp", "r", stdin); freopen(FileName".out", "w", stdout); #endif // Karma Enter(); Solve(); 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...