Submission #646544

# Submission time Handle Problem Language Result Execution time Memory
646544 2022-09-30T03:06:40 Z kith14 Collecting Mushrooms (NOI18_collectmushrooms) C++17
100 / 100
1220 ms 50760 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define db double
#define pairll pair<ll,ll>
#define lpairll pair<ll,pairll>

#define repp(i,a,b) for (ll i = a; i <= b; i++)
#define repz(i,a,b) for (ll i = a; i < b; i++)
#define repm(i,a,b) for (ll i = a; i >= b; i--)
#define fr first
#define sc second
#define x first
#define y second
#define mp make_pair
#define pb push_back

const ll N = 5e5+5, MOD = 1e9+7;
ll tc = 1, n, m, br[N], d, k;
string s, s1, s2, ye = "YA", no = "TIDAK";

void input(){
  cin >> n >> m >> d >> k;
}

void solve(){
  ll pr[n+5][m+5];
  ll mush[n+5][m+5];
  memset(pr,0,sizeof(pr));
  memset(mush,0,sizeof(mush));
  repp(i,1,n){
    repp(j,1,m){
      char bnk; cin >> bnk;
      if (bnk == 'S'){
        ll xa, ya, xb, yb;
        xa = max(1LL,i-d);
        ya = max(1LL,j-d);
        xb = min(n,i+d);
        yb = min(m,j+d);
        pr[xa][ya]++;
        pr[xa][yb+1]--;
        pr[xb+1][ya]--;
        pr[xb+1][yb+1]++;
      }
      else if (bnk == 'M'){
        mush[i][j] = 1;
      }
    }
  }
  ll ans = 0;
  repp(i,1,n){
    repp(j,1,m){
      pr[i][j] += pr[i-1][j]+pr[i][j-1]-pr[i-1][j-1];
      if (mush[i][j] && pr[i][j] >= k) ans++;
      cerr << pr[i][j] << " ";
    }
    cerr << endl;
  }
  cout << ans << endl;
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  //cin >> tc;
  while(tc--){
    input();
    solve();
  }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 21 ms 508 KB Output is correct
3 Correct 23 ms 520 KB Output is correct
4 Correct 6 ms 340 KB Output is correct
5 Correct 7 ms 388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 21 ms 508 KB Output is correct
3 Correct 23 ms 520 KB Output is correct
4 Correct 6 ms 340 KB Output is correct
5 Correct 7 ms 388 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 24 ms 468 KB Output is correct
9 Correct 7 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 348 KB Output is correct
2 Correct 9 ms 332 KB Output is correct
3 Correct 23 ms 512 KB Output is correct
4 Correct 3 ms 328 KB Output is correct
5 Correct 13 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 479 ms 4208 KB Output is correct
2 Correct 470 ms 4580 KB Output is correct
3 Correct 585 ms 5376 KB Output is correct
4 Correct 503 ms 4584 KB Output is correct
5 Correct 561 ms 4420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1220 ms 50752 KB Output is correct
2 Correct 1180 ms 49340 KB Output is correct
3 Correct 1190 ms 50568 KB Output is correct
4 Correct 1188 ms 50760 KB Output is correct
5 Correct 1217 ms 50652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 21 ms 508 KB Output is correct
3 Correct 23 ms 520 KB Output is correct
4 Correct 6 ms 340 KB Output is correct
5 Correct 7 ms 388 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 24 ms 468 KB Output is correct
9 Correct 7 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 6 ms 348 KB Output is correct
12 Correct 9 ms 332 KB Output is correct
13 Correct 23 ms 512 KB Output is correct
14 Correct 3 ms 328 KB Output is correct
15 Correct 13 ms 456 KB Output is correct
16 Correct 479 ms 4208 KB Output is correct
17 Correct 470 ms 4580 KB Output is correct
18 Correct 585 ms 5376 KB Output is correct
19 Correct 503 ms 4584 KB Output is correct
20 Correct 561 ms 4420 KB Output is correct
21 Correct 1220 ms 50752 KB Output is correct
22 Correct 1180 ms 49340 KB Output is correct
23 Correct 1190 ms 50568 KB Output is correct
24 Correct 1188 ms 50760 KB Output is correct
25 Correct 1217 ms 50652 KB Output is correct
26 Correct 1186 ms 13436 KB Output is correct
27 Correct 1165 ms 11748 KB Output is correct
28 Correct 1148 ms 12976 KB Output is correct
29 Correct 1138 ms 12364 KB Output is correct
30 Correct 1181 ms 12684 KB Output is correct