Submission #733389

# Submission time Handle Problem Language Result Execution time Memory
733389 2023-04-30T16:02:45 Z vjudge1 Collecting Mushrooms (NOI18_collectmushrooms) C++17
27 / 100
2000 ms 8388 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ld long double
#define ll long long
#define S second
#define F first
 
using namespace __gnu_pbds;
using namespace std;
 
typedef tree<long long, null_type, less_equal<long long>,
    rb_tree_tag, tree_order_statistics_node_update> Tree;
 
const ll INF = 9223372036854775807LL;
const ll inf = 2147483647;
const ll MAXN = 200010;
const ll MOD = 1e9 + 7;
const ld PI = acos(-1);
const ll NROOT = 320;
 
ll binpow(ll a, ll b) {
  ll res = 1;
  for (;b; b /= 2, a *= a, a %= MOD)
    if (b & 1) res *= a, res %= MOD;
  return res % MOD;
}
 
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
ll invmod(ll a) {return binpow(a, MOD - 2);}

int32_t main () {
  ios_base::sync_with_stdio(false); 
  cin.tie(nullptr);

  int n, m, D, k; cin >> n >> m >> D >> k;
  vector<vector<char>> M(n, vector<char> (m));
  vector<vector<int>> v(n, vector<int> (m));

  vector<pair<int, int>> H;
  for (int i = 0; i < n; i ++) {
    for (int j = 0; j < m; j ++) {
      cin >> M[i][j];
      if (M[i][j] == 'M') 
        H.push_back({i, j});
    }
  }

  int cnt = 0;
  vector<vector<int>> vis(n, vector<int> (m));
  for (int i = 0; i < n; i ++) {
    for (int j = 0; j < m; j ++) {
      if (M[i][j] == 'S') {
        cnt ++;
        queue<pair<pair<int, int>, pair<int, int>>> q;
        q.push({{i, j}, {i, j}});
        while (!q.empty()) {
          int x = q.front().F.F;
          int y = q.front().F.S;
          int dx = q.front().S.F;
          int dy = q.front().S.S;
          q.pop();
          if (x < 0 || y < 0 || x == n || y == m) continue;
          if (abs(dy - y) > D || abs(dx - x) > D) continue;
          if (vis[x][y] == cnt) continue;
          vis[x][y] = cnt;

          v[x][y] ++;
        
          q.push({{x + 1, y}, {dx, dy}});
          q.push({{x - 1, y}, {dx, dy}});
          q.push({{x, y + 1}, {dx, dy}});
          q.push({{x, y - 1}, {dx, dy}});
        }
      }
    }
  }

  /*for (int i = 0; i < n; i ++) {
    for (int j = 0; j < m; j ++) {
      cout << v[i][j] << " ";
    } cout << "\n";
  }*/

  int ans = 0;
  for (auto &[x, y] : H) {
    //cout << v[x][y] << '\n';
    if (v[x][y] >= k)
      ans ++;
  }

  cout << ans << "\n";

  return 0;
} 
# Verdict Execution time Memory Grader output
1 Correct 4 ms 212 KB Output is correct
2 Correct 1234 ms 572 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 27 ms 372 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 212 KB Output is correct
2 Correct 1234 ms 572 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 27 ms 372 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 7 ms 332 KB Output is correct
7 Correct 63 ms 320 KB Output is correct
8 Execution timed out 2056 ms 436 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 648 ms 2456 KB Output is correct
2 Execution timed out 2091 ms 2508 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2061 ms 8388 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 212 KB Output is correct
2 Correct 1234 ms 572 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 27 ms 372 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 7 ms 332 KB Output is correct
7 Correct 63 ms 320 KB Output is correct
8 Execution timed out 2056 ms 436 KB Time limit exceeded
9 Halted 0 ms 0 KB -