제출 #392037

#제출 시각아이디문제언어결과실행 시간메모리
392037strawberry2005Collecting Mushrooms (NOI18_collectmushrooms)C++17
100 / 100
18 ms12556 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define F first #define S second #define mp make_pair const int mod = 1e9+7; #define deb(x) cout<<#x<<": "<<x<<endl int iceil(int a, int b) { return (a + b - 1) / b; } int mul(int a, int b) { return a * 1ll * b % mod; } int binpow(int a, int b) { int res = 1; while (b) { if (b & 1) res = mul(res, a); a = mul(a, a); b >>= 1; } return res; } int ar[1001][1001]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.precision(20); #ifdef strawberryshaker2005 freopen("input.txt", "r", stdin); #endif int r,c,d,k; cin>>r>>c>>d>>k; char grid[r+1][c+1]; for(int i=1;i<=r;i++) for(int j=1;j<=c;j++) cin>>grid[i][j]; int diff[r+2][c+2]; memset(diff,0,sizeof(diff)); for(int i=1;i<=r;i++){ for(int j=1;j<=c;j++){ if(grid[i][j]=='S'){ diff[max(1LL,i-d)][max(1LL,j-d)]++; diff[min(r,i+d)+1][min(c,j+d)+1]++; diff[min(r,i+d)+1][max(1LL,j-d)]--; diff[max(1LL,i-d)][min(c,j+d)+1]--; } } } for(int i=1;i<=r;i++){ for(int j=1;j<=c;j++){ diff[i][j]+=diff[i-1][j]+diff[i][j-1]-diff[i-1][j-1]; } } int ans=0; for(int i=1;i<=r;i++){ for(int j=1;j<=c;j++){ if(diff[i][j]>=k&&grid[i][j]=='M') ans++; } } cout<<ans<<endl; return(0); }
#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...