Submission #1029713

# Submission time Handle Problem Language Result Execution time Memory
1029713 2024-07-21T08:28:33 Z 7again Collecting Mushrooms (NOI18_collectmushrooms) C++17
19 / 100
19 ms 20828 KB
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
#define f first
#define s second
#define pb push_back
#define in insert
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define FAST ios::sync_with_stdio(0);cout.tie(0);cin.tie(0)

using namespace std ;

void setIO(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}

const int N = 300000 , MOD = 1e9+7 ;

//bool inside(int x,int y){return(x<n&&y<m&&x>-1&&y>-1&&a[x][y]!='#');}

//int dx[4]{1 , -1 , 0 , 0} , dy[4]{0 , 0 , 1 , -1} ;


void slv()
{
    int n , m , d , k ;
    cin >> n >> m >> d >> k ;

    char a[n + 1][m + 1] ;
    int pfx[n + 4][m + 4] ;
    fill_n(&pfx[0][0] , (n + 4) * (m + 4) , 0) ;

    for(int i = 1 ; i <= n ; i++)
    {
        for(int j = 1 ; j <= m ; j++)
        {
            cin >> a[i][j] ;
            if(a[i][j] == 'S')
            {
                int x1 = max((int)1 , i - d) ;
                int x2 = min((int)n + 1 , i + d) ;
                int y1 = max((int)1 , j - d) ;
                int y2 = min((int)m + 1 , j + d) ;

                pfx[x1][y1]++ ;
                pfx[x1 - 1][y2 + 1]-- ;
                pfx[x2 + 1][y1 - 1]-- ;
                pfx[x2 + 1][y2 + 1]-- ;
            }
        }
    }

    for(int i = 1 ; i <= n ; i++)
    {
        for(int j = 1 ; j <= m ; j++)
        {
            pfx[i][j] += pfx[i - 1][j] ;
            pfx[i][j] += pfx[i][j - 1] ;
            pfx[i][j] -= pfx[i - 1][j - 1] ;
        }
    }

    int ans = 0 ;
    for(int i = 1 ; i <= n ; i++)
    {
        for(int j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == 'M' && pfx[i][j] >= k)
                ans++ ;
        }
    }

    cout << ans ;

}
main()
{
    //setIO("lasers") ;

    FAST ;

    int t = 1 ;
    //cin >> t ;

    while(t--)
        slv() ;
}

Compilation message

mushrooms.cpp:77:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   77 | main()
      | ^~~~
mushrooms.cpp: In function 'void setIO(std::string)':
mushrooms.cpp:16:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 | void setIO(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mushrooms.cpp:16:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 | void setIO(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 20828 KB Output is correct
2 Incorrect 17 ms 20828 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Incorrect 0 ms 348 KB Output isn't correct
12 Halted 0 ms 0 KB -