이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll tt=1; //cin>>tt;
while(tt--) {
ll r,c,d,k; cin>>r>>c>>d>>k;
ll grid[r+1][c+1];
for (ll i=0;i<=r;i++) {
grid[i][0]=0;
}
for (ll i=0;i<=c;i++) {
grid[0][i]=0;
}
vector<pair<ll,ll>> mush;
for (ll i=1;i<=r;i++) {
string s; cin>>s;
for (ll j=1;j<=c;j++) {
if (s[j-1]=='M') {
pair<ll,ll> p;
p.first=i; p.second=j;
mush.push_back(p);
}
grid[i][j]=grid[i-1][j]+grid[i][j-1]-grid[i-1][j-1];
if (s[j-1]=='S') grid[i][j]++;
}
}
ll ans=0;
for (auto p:mush) {
ll x1=p.first-d,x2=p.first+d,y1=p.second-d,y2=p.second+d;
x1=max(x1-1,(ll) 0); x2=min(x2,c);
y1=max(y1-1,(ll) 0); y2=min(y2,r);
ll count=grid[x2][y2]-grid[x1][y2]-grid[x2][y1]+grid[x1][y1];
if (count>=k) {
ans++;
}
}
cout<<ans<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |