Submission #426032

#TimeUsernameProblemLanguageResultExecution timeMemory
426032AmylopectinCollecting Mushrooms (NOI18_collectmushrooms)C++14
100 / 100
11 ms3736 KiB
#include <iostream>
#include <stdio.h>
using namespace std;
const int mxn = 1e6 + 10;
char s[mxn] = {},sf[mxn] = {};
int qsu[mxn] = {};
int fimi(int l,int r)
{
    if(l < r)
        return l;
    return r;
}
int fima(int l,int r)
{
    if(l > r)
        return l;
    return r;
}
int main()
{
    int i,j,n,m,k,d,nl,nr,ml,mr,ans = 0;
    scanf("%d %d %d %d",&n,&m,&d,&k);
    for(i=0; i<n; i++)
    {
        scanf("%s",&sf);
//        scanf("%s",&(s)+i*m);
        for(j=0; j<m; j++)
        {
            s[i*m + j] = sf[j];
            if(s[i*m + j] == 'S')
            {
                nl = fima(0,i-d);
                nr = fimi(n,i+d+1);
                ml = fima(0,j-d);
                mr = fimi(m,j+d+1);
                qsu[nl*m+ml] ++;
                if(mr < m)
                    qsu[nl*m+mr] --;
                if(nr < n)
                    qsu[nr*m+ml] --;
                if(mr < m && nr < n)
                    qsu[nr*m+mr] ++;
            }
        }
    }
    for(i=1; i<n; i++)
    {
        for(j=0; j<m; j++)
        {
            qsu[i*m + j] += qsu[(i-1)*m + j];
        }
    }
    for(i=0; i<n; i++)
    {
        for(j=1; j<m; j++)
        {
            qsu[i*m + j] += qsu[i*m + j - 1];
        }
    }
    for(i=0; i<n; i++)
    {
        for(j=0; j<m; j++)
        {
            if(s[i*m + j] == 'M')
            {
                if(qsu[i*m+j] >= k)
                {
                    ans ++;
                }
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}

Compilation message (stderr)

mushrooms.cpp: In function 'int main()':
mushrooms.cpp:25:17: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[1000010]' [-Wformat=]
   25 |         scanf("%s",&sf);
      |                ~^  ~~~
      |                 |  |
      |                 |  char (*)[1000010]
      |                 char*
mushrooms.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%d %d %d %d",&n,&m,&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",&sf);
      |         ~~~~~^~~~~~~~~~
#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...