Submission #586363

#TimeUsernameProblemLanguageResultExecution timeMemory
586363hibikiCollecting Mushrooms (NOI18_collectmushrooms)C++11
100 / 100
36 ms19700 KiB
#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 (stderr)

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);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#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...