제출 #535355

#제출 시각아이디문제언어결과실행 시간메모리
535355MedalistSlayerCollecting Mushrooms (NOI18_collectmushrooms)C++14
100 / 100
14 ms11312 KiB
#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);
}

컴파일 시 표준 에러 (stderr) 메시지

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);
      |         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...