Submission #394318

# Submission time Handle Problem Language Result Execution time Memory
394318 2021-04-26T11:58:04 Z ZenWoR Collecting Mushrooms (NOI18_collectmushrooms) C++14
100 / 100
22 ms 14696 KB
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

#define ll long long
#define ar array<int>
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()

using namespace std;

//https://oj.uz/problem/view/NOI18_collectmushrooms

vector<pair<int,int>> coords;
int R,C,D,K;

void solve() {
  cin>>R>>C>>D>>K;
  vector<vector<int>> t(R+3,vector<int>(C+3));
  vector<vector<char>> a(R+3,vector<char>(C+3));
  for(int i=1;i<=R;i++) {
    for(int j=1;j<=C;j++) {
      cin>>a[i][j];
      if(a[i][j]=='S')
        coords.push_back({i,j});
    }
  }
  if(!coords.size()) {
    cout<<0<<endl;
    return;
  }
  for(auto& e: coords) {
    int x=e.first,y=e.second;
    int x1=x-D,y1=y-D;
    int x2=x+D,y2=y+D;
    x1=max(x1,1);
    x2=min(x2,R);
    y1=max(y1,1);
    y2=min(y2,C);
//    cout<<"("<<x<<","<<y<<"): "<<x1<<" "<<y1<<"; "<<x2<<" "<<y2<<endl;
    t[x1][y1]++;
    t[x2+1][y2+1]++;
    t[x1][y2+1]--;
    t[x2+1][y1]--;
  }
  ll ans=0;
  for(int i=2;i<=R;i++) {
    for(int j=1;j<=C;j++) {
      t[i][j]+=t[i-1][j];
    }
  }
  for(int i=1;i<=R;i++) {
    for(int j=2;j<=C;j++) {
      t[i][j]+=t[i][j-1];
    }
  }
  for(int i=1;i<=R;i++) {
    for(int j=1;j<=C;j++) {
//      cout<<t[i][j]<<" ";
      if(a[i][j]=='M' and t[i][j]>=K)
        ans++;
    }
//    cout<<endl;
  }
  cout<<ans<<endl;
}

signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T=1;
//cin>>T;
while(T--)
    solve();

return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1228 KB Output is correct
2 Correct 5 ms 1356 KB Output is correct
3 Correct 6 ms 1484 KB Output is correct
4 Correct 5 ms 1356 KB Output is correct
5 Correct 6 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 12080 KB Output is correct
2 Correct 16 ms 11112 KB Output is correct
3 Correct 17 ms 11240 KB Output is correct
4 Correct 22 ms 14696 KB Output is correct
5 Correct 20 ms 12456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 5 ms 1228 KB Output is correct
17 Correct 5 ms 1356 KB Output is correct
18 Correct 6 ms 1484 KB Output is correct
19 Correct 5 ms 1356 KB Output is correct
20 Correct 6 ms 1388 KB Output is correct
21 Correct 19 ms 12080 KB Output is correct
22 Correct 16 ms 11112 KB Output is correct
23 Correct 17 ms 11240 KB Output is correct
24 Correct 22 ms 14696 KB Output is correct
25 Correct 20 ms 12456 KB Output is correct
26 Correct 19 ms 6468 KB Output is correct
27 Correct 14 ms 3912 KB Output is correct
28 Correct 20 ms 5588 KB Output is correct
29 Correct 15 ms 4540 KB Output is correct
30 Correct 21 ms 5644 KB Output is correct