Submission #93070

# Submission time Handle Problem Language Result Execution time Memory
93070 2019-01-06T11:19:49 Z win11905 Collecting Mushrooms (NOI18_collectmushrooms) C++11
100 / 100
25 ms 19896 KB
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author win11905
 */

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define iii tuple<int, int, int>
#define long long long
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const long MOD = 1e9+7, LINF = 1e18 + 1e16;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};

const int N = 1e6+5;

class collectmushrooms {
private:
    vector<vi> qs;
    vector<pii> vec;
    int n, m, d, k, ans;
    char inp[N];
public:
    void solve(istream& cin, ostream& cout) {
        cin >> n >> m >> d >> k;
        qs = vector<vi>(n+5, vi(m+5));
        for(int i = 1; i <= n; ++i) {
            cin >> inp+1;
            auto fx = [&](int v) {
                if(v > n) v = n+1;
                if(v < 1) v = 1;
                return v;
            };
            auto fy = [&](int v) {
                if(v > m) v = m+1;
                if(v < 1) v = 1;
                return v;
            };
            for(int j = 1; j <= m; ++j) {
                if(inp[j] == 'S') {
                    qs[fx(i-d)][fy(j-d)]++;
                    qs[fx(i+d+1)][fy(j-d)]--;
                    qs[fx(i-d)][fy(j+d+1)]--;
                    qs[fx(i+d+1)][fy(j+d+1)]++;
                }
                if(inp[j] == 'M') vec.emplace_back(i, j);
            }
        }
        for(int i = 1; i <= n; ++i) {
            for(int j = 1; j <= m; ++j) {
                qs[i][j] += qs[i-1][j] + qs[i][j-1] - qs[i-1][j-1];
            }
        }
        for(auto v : vec) {
            int x, y; tie(x, y) = v;
            if(qs[x][y] >= k) ans++;
        }
        cout << ans << endl;
    }
};

class Solver {
public:
    void solve(std::istream& in, std::ostream& out) {
        collectmushrooms *obj = new collectmushrooms();
        obj->solve(in, out);
    }
};

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    Solver solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}

Compilation message

mushrooms.cpp: In member function 'void collectmushrooms::solve(std::istream&, std::ostream&)':
mushrooms.cpp:34:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
             cin >> inp+1;
                    ~~~^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1272 KB Output is correct
2 Correct 3 ms 1400 KB Output is correct
3 Correct 3 ms 1404 KB Output is correct
4 Correct 3 ms 1400 KB Output is correct
5 Correct 3 ms 1400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1272 KB Output is correct
2 Correct 3 ms 1400 KB Output is correct
3 Correct 3 ms 1404 KB Output is correct
4 Correct 3 ms 1400 KB Output is correct
5 Correct 3 ms 1400 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 2 ms 1272 KB Output is correct
8 Correct 3 ms 1400 KB Output is correct
9 Correct 2 ms 1400 KB Output is correct
10 Correct 2 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1272 KB Output is correct
2 Correct 2 ms 1400 KB Output is correct
3 Correct 3 ms 1656 KB Output is correct
4 Correct 2 ms 1400 KB Output is correct
5 Correct 3 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2296 KB Output is correct
2 Correct 4 ms 2296 KB Output is correct
3 Correct 4 ms 2684 KB Output is correct
4 Correct 4 ms 2424 KB Output is correct
5 Correct 4 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 16852 KB Output is correct
2 Correct 21 ms 19796 KB Output is correct
3 Correct 24 ms 19896 KB Output is correct
4 Correct 22 ms 17236 KB Output is correct
5 Correct 25 ms 19796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1272 KB Output is correct
2 Correct 3 ms 1400 KB Output is correct
3 Correct 3 ms 1404 KB Output is correct
4 Correct 3 ms 1400 KB Output is correct
5 Correct 3 ms 1400 KB Output is correct
6 Correct 3 ms 1272 KB Output is correct
7 Correct 2 ms 1272 KB Output is correct
8 Correct 3 ms 1400 KB Output is correct
9 Correct 2 ms 1400 KB Output is correct
10 Correct 2 ms 1272 KB Output is correct
11 Correct 3 ms 1272 KB Output is correct
12 Correct 2 ms 1400 KB Output is correct
13 Correct 3 ms 1656 KB Output is correct
14 Correct 2 ms 1400 KB Output is correct
15 Correct 3 ms 1528 KB Output is correct
16 Correct 4 ms 2296 KB Output is correct
17 Correct 4 ms 2296 KB Output is correct
18 Correct 4 ms 2684 KB Output is correct
19 Correct 4 ms 2424 KB Output is correct
20 Correct 4 ms 2424 KB Output is correct
21 Correct 21 ms 16852 KB Output is correct
22 Correct 21 ms 19796 KB Output is correct
23 Correct 24 ms 19896 KB Output is correct
24 Correct 22 ms 17236 KB Output is correct
25 Correct 25 ms 19796 KB Output is correct
26 Correct 13 ms 6128 KB Output is correct
27 Correct 11 ms 5868 KB Output is correct
28 Correct 11 ms 5104 KB Output is correct
29 Correct 10 ms 5140 KB Output is correct
30 Correct 12 ms 6892 KB Output is correct