Submission #970429

# Submission time Handle Problem Language Result Execution time Memory
970429 2024-04-26T14:03:41 Z NoMercy Collecting Mushrooms (NOI18_collectmushrooms) C++17
0 / 100
28 ms 27184 KB
#include <bits/stdc++.h>
using namespace std;
 
    
 
#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;
    string c[n];
    vector<vector<int>> pre(n + 2 , vector<int> (m + 2 , 0));
    for (int i = 0;i < n;i ++) {
        cin >> c[i];
    }
    for (int i = 1;i <= n;i ++) {
        for (int j = 1;j <= m;j ++) {
            assert(c[i - 1][j - 1] == 'S' || c[i - 1][j - 1] == 'M' || c[i - 1][j - 1] == '.');
            if (c[i - 1][j - 1] == '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];
            }
        }
    }
    // for (int i = 1;i <= n;i ++) {
    //     for (int j = 1;j <= m;j ++) {
    //         cout << pre[i][j] << " ";
    //     }
    //     cout << "\n";
    // }
    int res = 0;
    for (int i = 1;i <= m;i ++) {
        for (int j = 1;j <= m;j ++) {
            res += bool(c[i - 1][j - 1] == 'M' && pre[i][j] >= k);
        }
    }
    cout << res << endl;
}
 
/*
 
 
.......
.......
.......
.......
.......
 
*/
 
int32_t main () {
 
    /////    file
    
 
    int t = 1;
    // cin >> t;
 
    while (t --) {
        test_case();
    }
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 3932 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 28 ms 27184 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -