답안 #535355

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
535355 2022-03-10T05:48:55 Z MedalistSlayer Collecting Mushrooms (NOI18_collectmushrooms) C++14
100 / 100
14 ms 11312 KB
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
 
using namespace std;

const int N = (int)5e5+10;
int R, C;
int D, K;
char str[N];

int main() {
    scanf("%d%d%d%d", &R, &C, &D, &K);
    int ans = 0;
    vector<vector<int>> pref(R + 1, vector<int>(C + 1, 0));
    vector<pair<int, int>> loc;
    for (int r = 1; r <= R; r++) {
        scanf("%s", str + 1);
        for (int c = 1; c <= C; c++) {
            char x = str[c];
            pref[r][c] = pref[r - 1][c] + pref[r][c - 1] - pref[r - 1][c - 1] + (x == 'S');
            if (x == 'M') {
                loc.emplace_back(r, c);
            }
        }
    }
    
    for (auto &[r, c] : loc) {
        int mnr = max(1, (r - D));
        int mnc = max(1, (c - D));
        int mxr = min(R, (r + D));
        int mxc = min(C, (c + D));

        int around = pref[mxr][mxc] - pref[mxr][mnc - 1] - pref[mnr - 1][mxc] + pref[mnr - 1][mnc - 1];
        ans += (around >= K);
    }

    printf("%d", ans);
}

Compilation message

mushrooms.cpp: In function 'int main()':
mushrooms.cpp:35:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   35 |     for (auto &[r, c] : loc) {
      |                ^
mushrooms.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     scanf("%d%d%d%d", &R, &C, &D, &K);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
mushrooms.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         scanf("%s", str + 1);
      |         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1208 KB Output is correct
2 Correct 3 ms 1236 KB Output is correct
3 Correct 3 ms 1552 KB Output is correct
4 Correct 3 ms 1236 KB Output is correct
5 Correct 3 ms 1300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 8496 KB Output is correct
2 Correct 13 ms 11312 KB Output is correct
3 Correct 13 ms 11312 KB Output is correct
4 Correct 11 ms 8752 KB Output is correct
5 Correct 14 ms 11312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 316 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 3 ms 1208 KB Output is correct
17 Correct 3 ms 1236 KB Output is correct
18 Correct 3 ms 1552 KB Output is correct
19 Correct 3 ms 1236 KB Output is correct
20 Correct 3 ms 1300 KB Output is correct
21 Correct 10 ms 8496 KB Output is correct
22 Correct 13 ms 11312 KB Output is correct
23 Correct 13 ms 11312 KB Output is correct
24 Correct 11 ms 8752 KB Output is correct
25 Correct 14 ms 11312 KB Output is correct
26 Correct 10 ms 4628 KB Output is correct
27 Correct 9 ms 4800 KB Output is correct
28 Correct 7 ms 3824 KB Output is correct
29 Correct 7 ms 3936 KB Output is correct
30 Correct 10 ms 5580 KB Output is correct