답안 #672907

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
672907 2022-12-19T01:33:36 Z vuavisao Collecting Mushrooms (NOI18_collectmushrooms) C++14
100 / 100
18 ms 23896 KB
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
using namespace std;

const int N =  + 10;

int n, m, k, d;
vector<string> s;

vector<vector<int>> pred;
int res;

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen("NOI18_collectmushrooms.inp", "r")) {
        freopen("NOI18_collectmushrooms.inp", "r", stdin);
        freopen("NOI18_collectmushrooms.out", "w", stdout);
    }
    cin >> n >> m >> d >> k;
    s.resize(n + 1);
    pred.resize(n + 10, vector<int> (m + 10, 0));
    for(int i = 1; i <= n; ++ i) {
        string w; cin >> w; w = ' ' + w;
        s[i] = w;
        for(int j = 1; j <= m; ++ j) {
            if(w[j] != 'S') continue;
            int le = max(j - d, 1), ri = min(j + d, m);
            int up = max(i - d, 1), down = min(i + d, n);
            ++ pred[up][le];
            -- pred[up][ri + 1];
            -- pred[down + 1][le];
            ++ pred[down + 1][ri + 1];
        }
    }
    for(int i = 1; i <= n; ++ i) {
        for(int j = 1; j <= m; ++ j) {
            pred[i][j] += pred[i - 1][j] + pred[i][j - 1] - pred[i - 1][j - 1];
            if(s[i][j] == 'M' && pred[i][j] >= k) {
                ++ res;
            }
        }
    }
    cout << res;
    return 0;
}

/// Code by vuavisao

Compilation message

mushrooms.cpp: In function 'int32_t main()':
mushrooms.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen("NOI18_collectmushrooms.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mushrooms.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen("NOI18_collectmushrooms.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 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 0 ms 316 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1488 KB Output is correct
2 Correct 3 ms 1504 KB Output is correct
3 Correct 3 ms 1876 KB Output is correct
4 Correct 2 ms 1612 KB Output is correct
5 Correct 2 ms 1620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23884 KB Output is correct
2 Correct 13 ms 23896 KB Output is correct
3 Correct 13 ms 23816 KB Output is correct
4 Correct 18 ms 23888 KB Output is correct
5 Correct 14 ms 23892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 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 0 ms 316 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 1488 KB Output is correct
17 Correct 3 ms 1504 KB Output is correct
18 Correct 3 ms 1876 KB Output is correct
19 Correct 2 ms 1612 KB Output is correct
20 Correct 2 ms 1620 KB Output is correct
21 Correct 14 ms 23884 KB Output is correct
22 Correct 13 ms 23896 KB Output is correct
23 Correct 13 ms 23816 KB Output is correct
24 Correct 18 ms 23888 KB Output is correct
25 Correct 14 ms 23892 KB Output is correct
26 Correct 13 ms 6260 KB Output is correct
27 Correct 6 ms 3376 KB Output is correct
28 Correct 8 ms 3788 KB Output is correct
29 Correct 6 ms 3580 KB Output is correct
30 Correct 10 ms 5076 KB Output is correct