답안 #586363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
586363 2022-06-30T07:24:38 Z hibiki Collecting Mushrooms (NOI18_collectmushrooms) C++11
100 / 100
36 ms 19700 KB
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()

int r, c, d, k;
vector<pair<int,int> > que;
vector<vector<int> > fen;

void up(int x, int y, int val)
{
    x = max(x, 1);
    y = max(y, 1);
    while(x <= r)
    {
        int ty = y;
        while(ty <= c)
        {
            fen[x][ty] += val;
            ty += ty & -ty;
        }
        x += x & -x;
    }
    return ;
}

void up(int x, int y)
{
    up(x - d, y - d, 1);
    up(x + d + 1, y - d, -1);
    up(x - d, y + d + 1, -1);
    up(x + d + 1, y + d + 1, 1);
}

int query(int x, int y)
{
    int ans = 0;
    while(x > 0)
    {
        int ty = y;
        while(ty > 0)
        {
            ans += fen[x][ty];
            ty -= ty & -ty;
        }
        x -= x & -x;
    }
    return ans;
}

int main()
{
    scanf("%d %d %d %d",&r,&c,&d,&k);
    char pic[r + 5][c + 5];
    fen.resize(r + 5);
    for(int i = 0; i < r + 5; i++)
        fen[i].resize(c + 5);
    for(int i = 1; i <= r; i++)
    {
        scanf("%s",pic[i] + 1);
        for(int j = 1; j <= c; j++)
        {
            if(pic[i][j] == 'M')
                que.pb({i,j});
            else if(pic[i][j] == 'S')
                up(i, j);
        }
    }
    int ans = 0;
    for(auto val: que)
    {
        int ret = query(val.f, val.s);
        if(ret >= k) ans++;
    }
    printf("%d\n",ans);
}

Compilation message

mushrooms.cpp: In function 'int main()':
mushrooms.cpp:57:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |     scanf("%d %d %d %d",&r,&c,&d,&k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
mushrooms.cpp:64:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         scanf("%s",pic[i] + 1);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 308 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 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1492 KB Output is correct
2 Correct 2 ms 1492 KB Output is correct
3 Correct 4 ms 1748 KB Output is correct
4 Correct 3 ms 1492 KB Output is correct
5 Correct 3 ms 1512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 17608 KB Output is correct
2 Correct 21 ms 19688 KB Output is correct
3 Correct 19 ms 19700 KB Output is correct
4 Correct 29 ms 17656 KB Output is correct
5 Correct 22 ms 19652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 308 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 212 KB Output is correct
12 Correct 1 ms 296 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 432 KB Output is correct
16 Correct 3 ms 1492 KB Output is correct
17 Correct 2 ms 1492 KB Output is correct
18 Correct 4 ms 1748 KB Output is correct
19 Correct 3 ms 1492 KB Output is correct
20 Correct 3 ms 1512 KB Output is correct
21 Correct 17 ms 17608 KB Output is correct
22 Correct 21 ms 19688 KB Output is correct
23 Correct 19 ms 19700 KB Output is correct
24 Correct 29 ms 17656 KB Output is correct
25 Correct 22 ms 19652 KB Output is correct
26 Correct 25 ms 5600 KB Output is correct
27 Correct 19 ms 5328 KB Output is correct
28 Correct 36 ms 4560 KB Output is correct
29 Correct 21 ms 4568 KB Output is correct
30 Correct 20 ms 6276 KB Output is correct