Submission #953197

# Submission time Handle Problem Language Result Execution time Memory
953197 2024-03-25T16:53:11 Z tmtxangel Mecho (IOI09_mecho) C++17
10 / 100
110 ms 9052 KB
#include <bits/stdc++.h>


#define lli long long
#define ld long double
#define tmt angel

using namespace std;
const int maxn = 802;
int vis[maxn][maxn], n, m;
char a[maxn][maxn];
int tim[maxn][maxn];
int hi, hj, sti, stj;
int x[4] = {1, -1, 0, 0};
int y[4] = {0, 0, 1, -1};
deque<pair<pair<int, int>, int>> s;
bool flag = false;
int bvis[maxn][maxn];

void gocheck(int i, int j, int cost)
{
    if(i < 1 || j < 1 || i > n || j > n || bvis[i][j] == 1 || a[i][j] == 'D') return;
    bvis[i][j] = 1;
    tim[i][j] = cost;
    s.push_back({{i, j}, cost});
}
void spread(int i, int j, int cost, int step)
{
    if(vis[hi][hj] == 1) return;
    if(i < 1 || j < 1 || i > n || j > n || vis[i][j] == 1 || (tim[i][j] < cost && bvis[i][j] ==1)) return;
    vis[i][j] = 1;
   //     cout << i << " " << j << " " << cost << " " << step << '\n';
    if(vis[hi][hj] == 1) return;
    if(step == m)
    {
        //tim[1][i][j] = cost;
        s.push_back({{i, j}, cost});
    }
    else
    {
       // tim[1][i][j] = cost;
          for(int f = 0; f < 4; f++)
          {
             spread(i + x[f], j + y[f], cost, step + 1);
            if(vis[hi][hj] == 1) break;
          }
    }
}

void Bfs()
{
    while(!s.empty())
    {
        int i = s.front().first.first;
        int j = s.front().first.second;
        int c = s.front().second;
        s.pop_front();
        for(int f = 0; f < 4; f++)
        {
            gocheck(i + x[f], j + y[f], c+1);
        }
    }
}

bool checked(int st)
{
    s.clear();
    flag = false;
   // if(st == 0) s.push_back({ {sti, stj},{2, 0} });
    for(int i = 1; i <= n; i++)
    {
    for(int j = 1; j <= n; j++)
    {
        vis[i][j] = a[i][j] == 'G' || a[i][j] == 'D' ? 0 : 1;
    }
    }
    s.push_back({{sti, stj}, st});
    while(!s.empty() && vis[hi][hj] == 0)
    {
         int i = s.front().first.first;
        int j = s.front().first.second;
        int c = s.front().second;
        s.pop_front();
        for(int f = 0; f < 4; f++)
        {
            spread(i + x[f], j + y[f], c+1, 1);
            if(vis[hi][hj] == 1) break;
        }
    }
       return vis[hi][hj] == 1;

}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
//   freopen(".INP", "r" , stdin);
//   freopen(".OUT", "w" , stdout);
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
    for(int j = 1; j <= n; j++)
    {
        cin >> a[i][j];
        if(a[i][j] == 'M')
        {
            vis[i][j] = 1;
            sti = i;
            stj = j;
        }
        else vis[i][j] = a[i][j] == 'G' ? 0 : 1;
        if(a[i][j] == 'D')
        {
            hi = i;
            hj = j;
        }
        if(a[i][j] == 'H')
        {
            s.push_back({{i, j}, 0});
            bvis[i][j] = 1;
        }
    }
}
Bfs();
tim[hi][hj] = 1e9;
 //cout << checked(1);
int low = 0, high = n, mid;
while(low <= high)
{
    mid = (low + high) / 2;
    if(checked(mid)) low = mid+1;
    else high = mid - 1;
}
cout << high;

return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Incorrect 2 ms 4444 KB Output isn't correct
3 Incorrect 1 ms 4444 KB Output isn't correct
4 Incorrect 1 ms 4444 KB Output isn't correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Incorrect 90 ms 8620 KB Output isn't correct
8 Incorrect 1 ms 4440 KB Output isn't correct
9 Incorrect 1 ms 4444 KB Output isn't correct
10 Correct 1 ms 4444 KB Output is correct
11 Incorrect 1 ms 4444 KB Output isn't correct
12 Incorrect 2 ms 4700 KB Output isn't correct
13 Incorrect 1 ms 4700 KB Output isn't correct
14 Correct 2 ms 6748 KB Output is correct
15 Incorrect 1 ms 4444 KB Output isn't correct
16 Incorrect 1 ms 4444 KB Output isn't correct
17 Incorrect 1 ms 4444 KB Output isn't correct
18 Incorrect 1 ms 4564 KB Output isn't correct
19 Incorrect 1 ms 4444 KB Output isn't correct
20 Incorrect 1 ms 4444 KB Output isn't correct
21 Incorrect 2 ms 4444 KB Output isn't correct
22 Incorrect 1 ms 4444 KB Output isn't correct
23 Incorrect 1 ms 4700 KB Output isn't correct
24 Incorrect 1 ms 4952 KB Output isn't correct
25 Incorrect 1 ms 6748 KB Output isn't correct
26 Incorrect 1 ms 4700 KB Output isn't correct
27 Incorrect 1 ms 6748 KB Output isn't correct
28 Incorrect 1 ms 4780 KB Output isn't correct
29 Incorrect 1 ms 6748 KB Output isn't correct
30 Incorrect 1 ms 4696 KB Output isn't correct
31 Incorrect 1 ms 6744 KB Output isn't correct
32 Incorrect 1 ms 4792 KB Output isn't correct
33 Incorrect 5 ms 7004 KB Output isn't correct
34 Incorrect 5 ms 6120 KB Output isn't correct
35 Correct 20 ms 7260 KB Output is correct
36 Incorrect 8 ms 7256 KB Output isn't correct
37 Incorrect 7 ms 6236 KB Output isn't correct
38 Correct 26 ms 7260 KB Output is correct
39 Incorrect 8 ms 7516 KB Output isn't correct
40 Incorrect 9 ms 6748 KB Output isn't correct
41 Correct 34 ms 7776 KB Output is correct
42 Incorrect 10 ms 7520 KB Output isn't correct
43 Incorrect 11 ms 7012 KB Output isn't correct
44 Correct 41 ms 7776 KB Output is correct
45 Incorrect 11 ms 7776 KB Output isn't correct
46 Incorrect 12 ms 7268 KB Output isn't correct
47 Correct 49 ms 7784 KB Output is correct
48 Incorrect 15 ms 7776 KB Output isn't correct
49 Incorrect 16 ms 7528 KB Output isn't correct
50 Correct 62 ms 8036 KB Output is correct
51 Incorrect 16 ms 8024 KB Output isn't correct
52 Incorrect 16 ms 8028 KB Output isn't correct
53 Correct 73 ms 8344 KB Output is correct
54 Incorrect 18 ms 8280 KB Output isn't correct
55 Incorrect 18 ms 8284 KB Output isn't correct
56 Correct 93 ms 8528 KB Output is correct
57 Incorrect 21 ms 8280 KB Output isn't correct
58 Incorrect 21 ms 8284 KB Output isn't correct
59 Correct 101 ms 8700 KB Output is correct
60 Incorrect 28 ms 8540 KB Output isn't correct
61 Incorrect 24 ms 8540 KB Output isn't correct
62 Correct 110 ms 8772 KB Output is correct
63 Incorrect 25 ms 8536 KB Output isn't correct
64 Incorrect 101 ms 8792 KB Output isn't correct
65 Incorrect 94 ms 8536 KB Output isn't correct
66 Incorrect 22 ms 8540 KB Output isn't correct
67 Correct 37 ms 8540 KB Output is correct
68 Incorrect 27 ms 8840 KB Output isn't correct
69 Incorrect 35 ms 8792 KB Output isn't correct
70 Incorrect 27 ms 8796 KB Output isn't correct
71 Incorrect 25 ms 8796 KB Output isn't correct
72 Incorrect 26 ms 8796 KB Output isn't correct
73 Incorrect 31 ms 9052 KB Output isn't correct
74 Incorrect 52 ms 9052 KB Output isn't correct
75 Incorrect 68 ms 9052 KB Output isn't correct
76 Incorrect 59 ms 9052 KB Output isn't correct
77 Incorrect 77 ms 9052 KB Output isn't correct
78 Correct 72 ms 8792 KB Output is correct
79 Incorrect 65 ms 9048 KB Output isn't correct
80 Incorrect 77 ms 9008 KB Output isn't correct
81 Incorrect 67 ms 8796 KB Output isn't correct
82 Incorrect 66 ms 8796 KB Output isn't correct
83 Incorrect 76 ms 8796 KB Output isn't correct
84 Incorrect 81 ms 8952 KB Output isn't correct
85 Incorrect 73 ms 8924 KB Output isn't correct
86 Incorrect 74 ms 8920 KB Output isn't correct
87 Incorrect 89 ms 8936 KB Output isn't correct
88 Incorrect 81 ms 8796 KB Output isn't correct
89 Incorrect 90 ms 8812 KB Output isn't correct
90 Incorrect 86 ms 8796 KB Output isn't correct
91 Incorrect 90 ms 9048 KB Output isn't correct
92 Incorrect 82 ms 8792 KB Output isn't correct