Submission #1029660

#TimeUsernameProblemLanguageResultExecution timeMemory
10296607againCollecting Mushrooms (NOI18_collectmushrooms)C++17
0 / 100
12 ms12636 KiB
#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][m] ; int pfx[n + 2][m + 2] ; fill_n(&pfx[0][0] , (n + 2) * (m + 2) , 0) ; for(int i = 0 ; i < n ; i++) { for(int j = 0 ; j < m ; j++) { cin >> a[i][j] ; if(a[i][j] == 'S') { int x1 = max((int)0 , i - d - 1) ; int x2 = min((int)n , i + d + 1) ; int y1 = max((int)0 , j - d - 1) ; int y2 = min((int)m , j + d + 1) ; pfx[x1 + 1][y1]++ ; if(x2 < 0 && y1 < 0) pfx[x2][y1]-- ; if(x1 < 0 && y2 < 0) pfx[x1][y2]-- ; if(x2 < 0 && y2 < 0) pfx[x2][y2]-- ; } } } for(int i = 0 ; i < n ; i++) { for(int j = 0 ; j < m ; j++) { if(i > 0) pfx[i][j] += pfx[i - 1][j] ; if(j > 0) pfx[i][j] += pfx[i][j - 1] ; if(i > 0 && j > 0) pfx[i][j] -= pfx[i - 1][j - 1] ; } } int ans = 0 ; for(int i = 0 ; i < n ; i++) { for(int j = 0 ; 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 (stderr)

mushrooms.cpp:83:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   83 | 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);}
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mushrooms.cpp: In function 'void slv()':
mushrooms.cpp:52:31: warning: array subscript -1 is below array bounds of 'long long int [(<anonymous> + 1)]' [-Warray-bounds]
   52 |                     pfx[x2][y2]-- ;
      |                     ~~~~~~~~~~^
mushrooms.cpp:52:31: warning: array subscript -1 is below array bounds of 'long long int [(<anonymous> + 1)]' [-Warray-bounds]
#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...