Submission #767735

# Submission time Handle Problem Language Result Execution time Memory
767735 2023-06-27T06:23:35 Z mgl_diamond Mecho (IOI09_mecho) C++14
37 / 100
242 ms 4984 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using il = pair<ll, ll>;

#define foru(i, l, r) for(int i=(l); i<=(r); ++i)
#define ford(i, l, r) for(int i=(l); i>=(r); --i)
#define fore(x, v) for(auto &x : v)
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

void setIO(string name) {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  if (!name.empty()) {
    freopen((name + ".in").c_str(), "r", stdin);
    freopen((name + ".out").c_str(), "w", stdout);
  }
}

const int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
const int LIM = 1e9;
const int N = 808;

int n, s, vi[N][N];
ii st, en;
vector<ii> hives;
char a[N][N];

bool e(int i, int j) { return i >= 1 && i <= n && j >= 1 && j <= n; }

void propaganda(vector<ii> &lst, int xet, int dis) {
  queue<pair<ii, int>> bfs;
  for(auto x : lst) bfs.push({x, 0});
  lst.clear();
  
  while (!bfs.empty()) {
    auto at = bfs.front(); bfs.pop();
    int x = at.fi.fi, y = at.fi.se;

    if (vi[x][y] == 2 && xet == 1) {
      continue;
    }

    if (at.se == dis) {
      lst.emplace_back(at.fi);
      continue;
    }

    foru(d, 0, 3) {
      int nx = x+dx[d], ny = y+dy[d];
      if (!e(nx, ny) || a[nx][ny] == 'T') continue;
      if (xet == 2 && a[nx][ny] == 'D') continue;
      if (vi[nx][ny] != 0) {
        if (xet == 1) continue;
        if (vi[nx][ny] == 2) continue; 
      }
      vi[nx][ny] = xet;
      bfs.push({{nx, ny}, at.se+1});
    }
  }
}

void out() {
  foru(i, 1, n) {
    foru(j, 1, n) cout << vi[i][j] << " ";
    cout << "\n";
  }
  cout << "---------\n";
}

bool can(int eat_time) {
  memset(vi, 0, sizeof(vi));
  vector<ii> me, bees;
  me.emplace_back(st);
  bees = hives;
  propaganda(bees, 2, eat_time);
  while (!me.empty()) {
    propaganda(me, 1, s);
    propaganda(bees, 2, 1);
  }
  return vi[en.fi][en.se] == 1;
}

int main() {
  setIO("");

  cin >> n >> s;
  foru(i, 1, n)
    foru(j, 1, n) {
      cin >> a[i][j];
      if (a[i][j] == 'M') st = {i, j};
      else if (a[i][j] == 'D') en = {i, j};
      else if (a[i][j] == 'H') hives.emplace_back(i, j);
    }

  int ans = 0;
  for(int z=n; z>0; z>>=1) 
    while (ans+z < 2*n && can(ans+z))
      ans += z;
  
  cout << ans;
}

Compilation message

mecho.cpp: In function 'void setIO(std::string)':
mecho.cpp:18:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     freopen((name + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen((name + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2772 KB Output is correct
2 Correct 2 ms 2772 KB Output is correct
3 Correct 2 ms 2768 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2772 KB Output is correct
7 Correct 175 ms 4420 KB Output is correct
8 Incorrect 2 ms 2900 KB Output isn't correct
9 Correct 2 ms 2772 KB Output is correct
10 Correct 2 ms 2892 KB Output is correct
11 Correct 2 ms 2772 KB Output is correct
12 Incorrect 2 ms 2900 KB Output isn't correct
13 Correct 2 ms 2900 KB Output is correct
14 Incorrect 2 ms 2900 KB Output isn't correct
15 Incorrect 2 ms 2772 KB Output isn't correct
16 Incorrect 1 ms 2900 KB Output isn't correct
17 Incorrect 2 ms 2904 KB Output isn't correct
18 Incorrect 3 ms 2896 KB Output isn't correct
19 Incorrect 2 ms 2900 KB Output isn't correct
20 Incorrect 2 ms 2900 KB Output isn't correct
21 Incorrect 2 ms 2900 KB Output isn't correct
22 Incorrect 2 ms 2900 KB Output isn't correct
23 Incorrect 2 ms 2900 KB Output isn't correct
24 Incorrect 2 ms 2900 KB Output isn't correct
25 Incorrect 2 ms 2900 KB Output isn't correct
26 Incorrect 2 ms 2900 KB Output isn't correct
27 Incorrect 2 ms 2900 KB Output isn't correct
28 Incorrect 2 ms 2896 KB Output isn't correct
29 Incorrect 3 ms 2900 KB Output isn't correct
30 Incorrect 2 ms 2900 KB Output isn't correct
31 Incorrect 2 ms 2900 KB Output isn't correct
32 Incorrect 2 ms 2900 KB Output isn't correct
33 Incorrect 17 ms 3280 KB Output isn't correct
34 Incorrect 7 ms 3168 KB Output isn't correct
35 Correct 20 ms 3284 KB Output is correct
36 Incorrect 35 ms 3260 KB Output isn't correct
37 Incorrect 13 ms 3356 KB Output isn't correct
38 Correct 25 ms 3296 KB Output is correct
39 Incorrect 27 ms 3412 KB Output isn't correct
40 Incorrect 10 ms 3412 KB Output isn't correct
41 Correct 32 ms 3412 KB Output is correct
42 Incorrect 39 ms 3412 KB Output isn't correct
43 Incorrect 13 ms 3528 KB Output isn't correct
44 Correct 37 ms 3540 KB Output is correct
45 Incorrect 40 ms 3592 KB Output isn't correct
46 Incorrect 13 ms 3668 KB Output isn't correct
47 Correct 47 ms 3624 KB Output is correct
48 Incorrect 66 ms 3692 KB Output isn't correct
49 Incorrect 20 ms 3668 KB Output isn't correct
50 Correct 70 ms 3828 KB Output is correct
51 Incorrect 53 ms 3804 KB Output isn't correct
52 Incorrect 18 ms 3812 KB Output isn't correct
53 Correct 69 ms 3828 KB Output is correct
54 Incorrect 74 ms 3804 KB Output isn't correct
55 Incorrect 24 ms 3804 KB Output isn't correct
56 Correct 91 ms 3920 KB Output is correct
57 Incorrect 71 ms 4008 KB Output isn't correct
58 Incorrect 22 ms 3928 KB Output isn't correct
59 Correct 94 ms 4036 KB Output is correct
60 Incorrect 150 ms 4128 KB Output isn't correct
61 Incorrect 44 ms 4140 KB Output isn't correct
62 Correct 103 ms 4052 KB Output is correct
63 Correct 130 ms 4160 KB Output is correct
64 Correct 124 ms 4148 KB Output is correct
65 Correct 156 ms 4152 KB Output is correct
66 Correct 219 ms 4152 KB Output is correct
67 Incorrect 153 ms 4284 KB Output isn't correct
68 Correct 127 ms 4192 KB Output is correct
69 Correct 102 ms 4180 KB Output is correct
70 Correct 125 ms 4204 KB Output is correct
71 Correct 129 ms 4200 KB Output is correct
72 Correct 205 ms 4188 KB Output is correct
73 Correct 103 ms 4984 KB Output is correct
74 Correct 193 ms 4744 KB Output is correct
75 Correct 217 ms 4592 KB Output is correct
76 Correct 192 ms 4592 KB Output is correct
77 Correct 221 ms 4580 KB Output is correct
78 Incorrect 165 ms 4932 KB Output isn't correct
79 Correct 195 ms 4548 KB Output is correct
80 Correct 228 ms 4556 KB Output is correct
81 Correct 217 ms 4696 KB Output is correct
82 Correct 203 ms 4516 KB Output is correct
83 Correct 158 ms 4864 KB Output is correct
84 Correct 216 ms 4504 KB Output is correct
85 Correct 204 ms 4456 KB Output is correct
86 Correct 223 ms 4688 KB Output is correct
87 Correct 200 ms 4496 KB Output is correct
88 Correct 160 ms 4708 KB Output is correct
89 Correct 203 ms 4408 KB Output is correct
90 Correct 231 ms 4660 KB Output is correct
91 Correct 198 ms 4396 KB Output is correct
92 Correct 242 ms 4732 KB Output is correct