답안 #335356

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
335356 2020-12-12T03:37:31 Z ncduy0303 Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
22 ms 5248 KB
#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;



void solve() {
    int r, c, d, k; cin >> r >> c >> d >> k;
    int ps[r + 1][c + 1] = {}; 
    char grid[r + 1][c + 1];
    for (int i = 1; i <= r; i++) {
        for (int j = 1; j <= c; j++) {
            cin >> grid[i][j];
            ps[i][j] = (grid[i][j] == 'S') + ps[i - 1][j] + ps[i][j - 1] - ps[i - 1][j - 1];
        }
    }
    int ans = 0;
    for (int i = 1; i <= r; i++) {
        for (int j = 1; j <= c; j++) {
            if (grid[i][j] == 'M') {
                int tli = max(1, i - d), tlj = max(1, j - d);
                int bri = min(r, i + d), brj = min(c, j + d);
                int cnt = ps[bri][brj] + ps[tli - 1][tlj - 1] - ps[tli - 1][brj] - ps[bri][tlj - 1];
                ans += (cnt >= k);
            }
        }
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc = 1;
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1516 KB Output is correct
2 Correct 5 ms 1516 KB Output is correct
3 Correct 6 ms 1772 KB Output is correct
4 Correct 5 ms 1516 KB Output is correct
5 Correct 5 ms 1644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 5228 KB Output is correct
2 Correct 13 ms 5228 KB Output is correct
3 Correct 16 ms 5228 KB Output is correct
4 Correct 13 ms 5248 KB Output is correct
5 Correct 14 ms 5228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 5 ms 1516 KB Output is correct
17 Correct 5 ms 1516 KB Output is correct
18 Correct 6 ms 1772 KB Output is correct
19 Correct 5 ms 1516 KB Output is correct
20 Correct 5 ms 1644 KB Output is correct
21 Correct 22 ms 5228 KB Output is correct
22 Correct 13 ms 5228 KB Output is correct
23 Correct 16 ms 5228 KB Output is correct
24 Correct 13 ms 5248 KB Output is correct
25 Correct 14 ms 5228 KB Output is correct
26 Correct 12 ms 3308 KB Output is correct
27 Correct 13 ms 3308 KB Output is correct
28 Correct 12 ms 3308 KB Output is correct
29 Correct 12 ms 3328 KB Output is correct
30 Correct 12 ms 3308 KB Output is correct