답안 #689761

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
689761 2023-01-29T10:22:57 Z zeroesandones Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
19 ms 16968 KB
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;

#define FOR(i, j, k) for (ll i = j; i < (ll) k; ++i)
#define FORD(i, j, k) for (ll i = j; i >= (ll) k; --i)
#define nl "\n"
#define sp " "

#define all(x) (x).begin(), (x).end()
#define sc second
#define fr first
#define pb push_back

void solve()
{
    ll n, m, d, k;
    cin >> n >> m >> d >> k;

    vector<pi> mush;
    ll sum[n + 1][m + 1] = {};

    FOR(i, 1, n + 1) {
        FOR(j, 1, m + 1) {
            char c;
            cin >> c;
            ll cost = 0;
            if(c == 'S')
                cost = 1;
            else if(c == 'M')
                mush.pb({i, j});
            sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + cost;
        }
    }

    ll ans = 0;
    for(auto [x, y] : mush) {
        ll leftN = max(1LL, x - d);
        ll rightN = min(x + d, n);
        ll leftM = max(1LL, y - d);
        ll rightM = min(y + d, m);

        ll curr = sum[rightN][rightM] - sum[leftN - 1][rightM] - sum[rightN][leftM - 1] + sum[leftN - 1][leftM - 1];
        if(curr >= k)
            ++ans;
    }

    cout << ans << nl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1992 KB Output is correct
2 Correct 4 ms 2004 KB Output is correct
3 Correct 4 ms 2516 KB Output is correct
4 Correct 4 ms 2124 KB Output is correct
5 Correct 5 ms 2256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 12736 KB Output is correct
2 Correct 19 ms 16968 KB Output is correct
3 Correct 19 ms 16968 KB Output is correct
4 Correct 17 ms 12804 KB Output is correct
5 Correct 19 ms 16968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 4 ms 1992 KB Output is correct
17 Correct 4 ms 2004 KB Output is correct
18 Correct 4 ms 2516 KB Output is correct
19 Correct 4 ms 2124 KB Output is correct
20 Correct 5 ms 2256 KB Output is correct
21 Correct 16 ms 12736 KB Output is correct
22 Correct 19 ms 16968 KB Output is correct
23 Correct 19 ms 16968 KB Output is correct
24 Correct 17 ms 12804 KB Output is correct
25 Correct 19 ms 16968 KB Output is correct
26 Correct 12 ms 6860 KB Output is correct
27 Correct 15 ms 8780 KB Output is correct
28 Correct 12 ms 6736 KB Output is correct
29 Correct 12 ms 6956 KB Output is correct
30 Correct 14 ms 8908 KB Output is correct