Submission #1133965

#TimeUsernameProblemLanguageResultExecution timeMemory
1133965vibeduckCollecting Mushrooms (NOI18_collectmushrooms)C++20
100 / 100
21 ms23272 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define pf push_front #define mp make_pair #define fi first #define se second #define int long long #define all(x) (x).begin(), (x).end() typedef long double ld; typedef long long ll; typedef pair<ll,ll> pll; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<bool> vb; typedef vector<vector<int>> vvi; typedef vector<vector<bool>> vvb; typedef vector<vector<ll>> vvll; typedef vector<string> vs; typedef vector<vector<string>> vvs; typedef vector<char> vc; typedef vector<vector<char>> vvc; typedef map<int, int> mii; typedef unordered_map<int, int> umii; const int mod = 1e9 + 7; const int inf = INTMAX_MAX; const bool tc = false; int sum(int x1, int x2, int y1, int y2, vvi &pfix) { x1 = max(x1, (int)0); y1 = max(y1, (int)0); x2 = min(x2, (int)pfix.size()-2); y2 = min(y2, (int)pfix[0].size()-2); x2++; y2++; //cout << x1 << " " << y1 << " " << x2 << " " << y2 << " query\n"; return pfix[x2][y2] - pfix[x2][y1] - pfix[x1][y2] + pfix[x1][y1]; //return 0; } inline void solve() { int r, c, d, k; cin >> r >> c >> d >> k; vector<pii> ms; vvi grid(r, vi(c, 0)); for (int i = 0; i < r; i++) for (int j = 0; j < c; j++) { char x; cin >> x; if (x == '.') continue; if (x == 'S') grid[i][j] = 1; if (x == 'M') ms.pb({i, j}); } vvi pfix(r + 1, vi(c + 1)); for (int i = 1; i <= r; i++) for (int j = 1; j <= c; j++) pfix[i][j] = pfix[i - 1][j] + pfix[i][j - 1] - pfix[i - 1][j - 1] + grid[i - 1][j - 1]; int ans = 0; for (auto &x : ms) { ans += (sum(x.fi - d, x.fi + d, x.se - d, x.se + d, pfix) >= k); } cout << ans << '\n'; //cout << "h\n"; } void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } signed main() { ios::sync_with_stdio(false); cout.tie(0); cin.tie(0); //setIO(); int t = 1; if (tc) { cin >> t; } while (t--) { solve(); } }

Compilation message (stderr)

mushrooms.cpp: In function 'void setIO(std::string)':
mushrooms.cpp:62:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mushrooms.cpp:63:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...