Submission #321064

#TimeUsernameProblemLanguageResultExecution timeMemory
321064nishuzCollecting Mushrooms (NOI18_collectmushrooms)C++14
18 / 100
19 ms13036 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ull unsigned long long #define ld long double #define F first #define S second #define eb emplace_back #define pb push_back #define mp make_pair #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) using namespace __gnu_pbds; using namespace std; template <typename T> using oset = tree <pair <T, T>, null_type, less <pair <T, T>>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> void ckmin(T& a, const T b) {a = min(a, b);} template <typename T> void ckmax(T& a, const T b) {a = max(a, b);} template <typename T> void print(vector <T> v) { for (T i : v) cout << i << " "; cout << '\n'; } template <typename T> void print(vector <vector <T>>& v) { for (vector <T>& vv : v) { for (T& i : vv) cout << i << " "; cout << '\n'; } } template <typename T> void read(vector <T>& v) {for (T& i : v) cin >> i;} template <typename T> void read(T&& t) {cin >> t;} template <typename T, typename... Args> void read(T&& t, Args&&... args) { cin >> t; read(forward<Args>(args)...); } template <typename T> void print(T&& t) {cout << t << '\n';} template <typename T, typename... Args> void print(T&& t, Args&&... args) { cout << t << " "; print(forward<Args>(args)...); } void usaco(string name = "") { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(name.size()) { freopen((name+".in").c_str(), "r", stdin); freopen((name+".txt").c_str(), "w", stdout); } } void solve() { int r, c, d, k, ans = 0; cin >> r >> c >> d >> k; int diff[r+2][c+2], dp[r+2][c+2]; char a[r+1][c+1]; for (int i = 1; i <= r; ++i) for (int j = 1; j <= c; ++j) cin >> a[i][j]; for (int i = 0; i <= r+1; ++i) for (int j = 0; j <= c+1; ++j) dp[i][j] = diff[i][j] = 0; auto valid = [&](int x, int y, int r, int c) { bool ok = 1; ok &= (x >= 0 && x <= r+1); ok &= (y >= 0 && y <= c+1); return ok; }; for (int i = 1; i <= r; ++i) { for (int j = 1; j <= c; ++j) { if (a[i][j] == 'S') { if (valid(i-d, j-d, r, c)) ++diff[i-d][j-d]; if (valid(i-d, j+d+1, r, c)) --diff[i-d][j+d+1]; if (valid(i+d+1, j-d, r, c)) --diff[i+d+1][j-d]; if (valid(i+d+1, j+d+1, r, c)) ++diff[i+d+1][j+d+1]; } } } for (int i = 0; i <= r; ++i) { for (int j = 0; j <= c; ++j) { if (i) dp[i][j] += dp[i-1][j]; if (j) dp[i][j] += dp[i][j-1]; if (i && j) dp[i][j] -= dp[i-1][j-1]; dp[i][j] += diff[i][j]; if (i && j) ans += (dp[i][j] >= k && a[i][j] == 'M'); } } print(ans); } int32_t main() { usaco(); int t = 1; while (t--) solve(); }

Compilation message (stderr)

mushrooms.cpp: In function 'void usaco(std::string)':
mushrooms.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   72 |         freopen((name+".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mushrooms.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   73 |         freopen((name+".txt").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...