답안 #970445

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970445 2024-04-26T14:25:32 Z NoMercy Collecting Mushrooms (NOI18_collectmushrooms) C++14
100 / 100
28 ms 13616 KB
#include <bits/stdc++.h>
using namespace std;
 
    
int TIME = clock();
 
#define file \
            freopen("in.txt" , "r" , stdin); \
            freopen("out.txt" , "w" , stdout);
 
#define int long long 
 
void test_case () {
    int n , m , d , k;
    cin >> n >> m >> d >> k;
    char c[n + 1][m + 1];
    int pre[n + 2][m + 2];
    for (int i = 0;i <= n + 1;i ++) {
        for (int j = 0;j <= m + 1;j ++) {
            pre[i][j] = 0;
        }
    }
    for (int i = 1;i <= n;i ++) {
        for (int j = 1;j <= m;j ++) {
            cin >> c[i][j];
        }
    }
    for (int i = 1;i <= n;i ++) {
        for (int j = 1;j <= m;j ++) {
            assert(c[i][j] == 'S' || c[i][j] == 'M' || c[i][j] == '.');
            if (c[i][j] == 'S') {
                pre[max(0LL , i - d)][max(0LL , j - d)] ++;
                pre[min(n + 1 , i + d + 1)][min(m + 1 , j + d + 1)] ++;
                pre[min(n + 1 , i + d + 1)][max(0LL , j - d)] --;
                pre[max(0LL , i - d)][min(m + 1 , j + d + 1)] --;
            }
        }
    }
    for (int i = 0;i <= n;i ++) {
        for (int j = 0;j <= m;j ++) {
            if (i > 0) {
                pre[i][j] += pre[i - 1][j];
            }
            if (j > 0) {
                pre[i][j] += pre[i][j - 1];
            }
            if (i > 0 && j > 0) {
                pre[i][j] -= pre[i - 1][j - 1];
            }
        }
    }
    
    int res = 0;
    for (int i = 1;i <= n;i ++) {
        for (int j = 1;j <= m;j ++) {
            res += bool(c[i][j] == 'M' && pre[i][j] >= k);
        }
    }
    cout << res << "\n";
}
 
/*
 
 
.......
.......
.......
.......
.......
 
*/
 
int32_t main () {
 
    ///    file
    
 
    int t = 1;
    // cin >> t;
 
    while (t --) {
        test_case();
    }
 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 432 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2136 KB Output is correct
2 Correct 9 ms 2396 KB Output is correct
3 Correct 10 ms 2896 KB Output is correct
4 Correct 10 ms 2396 KB Output is correct
5 Correct 9 ms 2588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 13148 KB Output is correct
2 Correct 26 ms 13404 KB Output is correct
3 Correct 28 ms 13616 KB Output is correct
4 Correct 28 ms 13404 KB Output is correct
5 Correct 27 ms 13400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 432 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 600 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 8 ms 2136 KB Output is correct
17 Correct 9 ms 2396 KB Output is correct
18 Correct 10 ms 2896 KB Output is correct
19 Correct 10 ms 2396 KB Output is correct
20 Correct 9 ms 2588 KB Output is correct
21 Correct 28 ms 13148 KB Output is correct
22 Correct 26 ms 13404 KB Output is correct
23 Correct 28 ms 13616 KB Output is correct
24 Correct 28 ms 13404 KB Output is correct
25 Correct 27 ms 13400 KB Output is correct
26 Correct 23 ms 5468 KB Output is correct
27 Correct 22 ms 5212 KB Output is correct
28 Correct 22 ms 5464 KB Output is correct
29 Correct 25 ms 5212 KB Output is correct
30 Correct 24 ms 5468 KB Output is correct