Submission #921539

#TimeUsernameProblemLanguageResultExecution timeMemory
921539vjudge1Collecting Mushrooms (NOI18_collectmushrooms)C++17
100 / 100
14 ms17392 KiB
#include <bits/stdc++.h> #include <iomanip> #define ll long long #define int long long #define pb push_back #define mp make_pair #define ff first #define ss second #define str string #define pii pair<int,int> #define sz(x) x.size() #define all(x) x.begin(), x.end() #define vi vector<int> #define mii map<int,int> #define mll map<ll,ll> #define yes cout<<"YES\n"; #define no cout<<"NO\n"; #define yess cout<<"Yes\n"; #define noo cout<<"No\n"; using namespace std; #define maxn 1111111 #define mod 1000000007 void solve(){ int n,m,k,l; cin>>n>>m>>k>>l; int pp[n+3][m+3]; for(int i=0;i<=n;i++){ pp[i][0]=0; } for(int i=0;i<=m;i++){ pp[0][i]=0; } str s[n+3],d; for(int i=1;i<=n;i++){ s[i]=" "; cin>>d; s[i]+=d; for(int j=1;j<=m;j++){ pp[i][j]=(s[i][j]=='S'); pp[i][j]+=pp[i-1][j]; pp[i][j]+=pp[i][j-1]; pp[i][j]-=pp[i-1][j-1]; } } int ans=0; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(s[i][j]!='M'){ continue; } int l1,l2,r1,r2; l1=max(1ll,i-k); l2=min(n,i+k); r1=max(1ll,j-k); r2=min(m,j+k); int c=pp[l2][r2]-pp[l1-1][r2]-pp[l2][r1-1]+pp[l1-1][r1-1]; if(c>=l){ ans++; } } } cout<<ans; } signed main(){ ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); //srand( time(0)); //freopen("sum.in", "r", stdin); //freopen("sum.out", "w", stdout); int tests=1; //cin>>tests; for(int i=1;i<=tests;i++){ //cout<<"Case "<<i<<": \n"; solve(); } }
#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...