Submission #1038760

# Submission time Handle Problem Language Result Execution time Memory
1038760 2024-07-30T07:19:16 Z Tepeyac Mecho (IOI09_mecho) C++11
68 / 100
123 ms 7016 KB
#include <bits/stdc++.h>

using namespace std;

int n, s;
char ma[801][801];
int enj[801][801];
int pa[801][801];

int r, c;
int r2, c2;

int mov[4][2] = { {1, 0}, {0, 1}, {-1, 0}, {0, -1} };

bool isvalidBee(int x, int y)
{
    if(!x || !y || x > n || y > n) 
    return false;

    if(ma[x][y] == 'T' || ma[x][y] == 'D') 
    return false;

    if(enj[x][y] != -1) 
    return false;

    return true;
}

void BeeFS()
{

    queue<pair<int, int> > q;
    pair<int, int> act;
    
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= n; ++j)
        {
            if(ma[i][j] == 'H')
            {
                q.push({i, j});
            }
            else
            enj[i][j] = -1;
        }
    }

    while(!q.empty())
    {
        act = q.front();
        q.pop();

        for(int i = 0; i < 4; ++i)
        {
            int nx = act.first + mov[i][0];
            int ny = act.second + mov[i][1];

            if(isvalidBee(nx, ny))
            {
                enj[nx][ny] = enj[act.first][act.second] + s;
                q.push({nx, ny});
            }

        }

    }

}

bool isvalidMecho(int x, int y, int time)
{
    if(!x || !y || x > n || y > n) 
    return false;

    if(ma[x][y] == 'T')
    return false;

    if(ma[x][y] == 'D')
    return true;

    if(pa[x][y] != -1)
    return false;

    if(time >= enj[x][y])
    return false;

    return true;

}

bool monotone(int m)
{

    queue<pair<int, int> > q;
    pair<int, int> act;

    for( int i = 1; i <= n; i++ )
		for( int j = 1; j <= n; j++ )
			pa[i][j] = -1;

    q.push({r, c});
    pa[r][c] = m * s;

    if(enj[r][c] <= pa[r][c]) return false;

    while(!q.empty())
    {
        act = q.front();
        q.pop();

        int time = pa[act.first][act.second] + 1;

        for(int i = 0; i < 4; ++i)
        {
            int nx = act.first + mov[i][0];
            int ny = act.second + mov[i][1];

            if(isvalidMecho(nx, ny, time))
            {
                q.push({nx, ny});
                pa[nx][ny] = time;

            }
        }
    }

    return pa[r2][c2] != -1;

}

int Binary(int a, int b)
{
    while(a != b)
    {
        int m = (a + b) / 2 + 1;

        if(monotone(m))
        {
            a = m;
        }
        else
        b = m - 1;
    }
    return a;
}

int main()
{

cin.tie(0) -> sync_with_stdio(0);

cin >> n >> s;

for(int i = 1; i <= n; ++i)
{
    for(int j = 1; j <= n; ++j)
    {
        cin >> ma[i][j];
        if(ma[i][j] == 'M')
        {
            r = i, c = j;
        }
        if(ma[i][j] == 'D')
        {
            r2 = i, c2 = j;
        }
    }
}

BeeFS();

int maxm = enj[r][c];

cout << Binary(0,  maxm);

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 464 KB Output is correct
7 Correct 67 ms 6672 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 860 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Incorrect 1 ms 860 KB Output isn't correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 464 KB Output is correct
18 Correct 0 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 0 ms 604 KB Output is correct
23 Correct 0 ms 604 KB Output is correct
24 Correct 0 ms 604 KB Output is correct
25 Correct 1 ms 856 KB Output is correct
26 Correct 1 ms 860 KB Output is correct
27 Correct 1 ms 860 KB Output is correct
28 Correct 1 ms 860 KB Output is correct
29 Correct 1 ms 860 KB Output is correct
30 Correct 1 ms 860 KB Output is correct
31 Correct 1 ms 860 KB Output is correct
32 Correct 1 ms 860 KB Output is correct
33 Correct 4 ms 2908 KB Output is correct
34 Correct 4 ms 2908 KB Output is correct
35 Correct 15 ms 2904 KB Output is correct
36 Correct 6 ms 3420 KB Output is correct
37 Correct 7 ms 3296 KB Output is correct
38 Correct 20 ms 3224 KB Output is correct
39 Correct 11 ms 3676 KB Output is correct
40 Correct 6 ms 3672 KB Output is correct
41 Correct 27 ms 3848 KB Output is correct
42 Correct 7 ms 4188 KB Output is correct
43 Correct 6 ms 4188 KB Output is correct
44 Correct 32 ms 4188 KB Output is correct
45 Correct 15 ms 4444 KB Output is correct
46 Incorrect 15 ms 4652 KB Output isn't correct
47 Correct 42 ms 4636 KB Output is correct
48 Correct 12 ms 4956 KB Output is correct
49 Incorrect 14 ms 5064 KB Output isn't correct
50 Correct 48 ms 4956 KB Output is correct
51 Correct 12 ms 5464 KB Output is correct
52 Incorrect 24 ms 5448 KB Output isn't correct
53 Correct 56 ms 5468 KB Output is correct
54 Correct 14 ms 5892 KB Output is correct
55 Incorrect 36 ms 5804 KB Output isn't correct
56 Correct 98 ms 5720 KB Output is correct
57 Correct 26 ms 6232 KB Output is correct
58 Incorrect 32 ms 6292 KB Output isn't correct
59 Correct 73 ms 6236 KB Output is correct
60 Correct 17 ms 6480 KB Output is correct
61 Incorrect 33 ms 6712 KB Output isn't correct
62 Correct 83 ms 6604 KB Output is correct
63 Correct 80 ms 6484 KB Output is correct
64 Correct 123 ms 6672 KB Output is correct
65 Correct 112 ms 6492 KB Output is correct
66 Correct 117 ms 6484 KB Output is correct
67 Incorrect 89 ms 6488 KB Output isn't correct
68 Correct 42 ms 6724 KB Output is correct
69 Correct 36 ms 6740 KB Output is correct
70 Correct 28 ms 6744 KB Output is correct
71 Correct 46 ms 6608 KB Output is correct
72 Correct 25 ms 6572 KB Output is correct
73 Correct 24 ms 6740 KB Output is correct
74 Correct 40 ms 7004 KB Output is correct
75 Correct 77 ms 7016 KB Output is correct
76 Correct 45 ms 7000 KB Output is correct
77 Correct 46 ms 7000 KB Output is correct
78 Incorrect 58 ms 6936 KB Output isn't correct
79 Correct 39 ms 6740 KB Output is correct
80 Correct 45 ms 6776 KB Output is correct
81 Correct 51 ms 6968 KB Output is correct
82 Correct 73 ms 6972 KB Output is correct
83 Correct 60 ms 6744 KB Output is correct
84 Correct 54 ms 6748 KB Output is correct
85 Correct 48 ms 6924 KB Output is correct
86 Correct 51 ms 6748 KB Output is correct
87 Correct 51 ms 6736 KB Output is correct
88 Correct 58 ms 6880 KB Output is correct
89 Correct 65 ms 6748 KB Output is correct
90 Correct 53 ms 6736 KB Output is correct
91 Correct 64 ms 6748 KB Output is correct
92 Correct 54 ms 6876 KB Output is correct