Submission #858178

# Submission time Handle Problem Language Result Execution time Memory
858178 2023-10-07T14:35:26 Z BBart888 Mecho (IOI09_mecho) C++14
21 / 100
182 ms 11408 KB
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <array>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <stack>
#include <stdio.h>      /* printf, scanf, puts, NULL */
#include <stdlib.h>     /* srand, rand */
#include <time.h> 
#include <unordered_map>
#include <string>
#include <fstream>



using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Mat = vector<vector<ll>>;

const ll MOD = 2019201997LL;
const ll FACTOR1 = 2019201913LL;
const ll FACTOR2 = 2019201949LL;
const int MAXN = 1e3 + 11;




int n, s, l, r;
char t[MAXN][MAXN];
vector<pair<int,int>>hives;
int dx[]{ 0,0,-1,1 };
int dy[]{ 1,-1,0,0 };
int dist[MAXN][MAXN];
pair<int, int> bear,house;




bool within(int x, int y)
{
    return (x >= 0 && y >= 0 && x < n&& y < n);
}


void action()
{
    queue<pair<int, int>> q;
    vector<vector<int>> vis(n, vector<int>(n));

    for (auto h : hives)
    {
        q.push(h);
        vis[h.first][h.second] = true;
    }

    while (!q.empty())
    {
        int x = q.front().first;
        int y = q.front().second;
        q.pop();

        for (int d = 0; d < 4; d++)
        {
            int newX = x + dx[d];
            int newY = y + dy[d];
            if (!within(newX, newY) || t[newX][newY] == 'T'
                || vis[newX][newY])
                continue;
            vis[newX][newY] = true;
            q.push({ newX,newY });
            dist[newX][newY] = dist[x][y] + 1;
        }
    }
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            dist[i][j] *= s;

}



bool check(int mins)
{
    queue<pair<int,int>> q;
    vector<vector<int>>bear_dist(n, vector<int>(n));
    vector<vector<int>> vis(n, vector<int>(n));

    q.push(bear);
    vis[bear.first][bear.second] = true;

    while (!q.empty())
    {
        int x = q.front().first;
        int y = q.front().second;
        q.pop();
        //cout << x << " " << y << " " << bear_dist[x][y] <<" VS "<<
           // dist[x][y]<<'\n';
        for (int d = 0; d < 4; d++)
        {
            int newX = x + dx[d];
            int newY = y + dy[d];
            if (!within(newX, newY) || (t[newX][newY] == 'T') || (
                bear_dist[x][y]+1> dist[newX][newY]-s*mins) || vis[newX][newY])
                continue;
            vis[newX][newY] = true;
            q.push({ newX,newY });
            bear_dist[newX][newY] = bear_dist[x][y] + 1;
        }

    }

    return bear_dist[house.first][house.second] > 0;
}



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    //freopen("lasers.in", "r", stdin);
    //freopen("lasers.out", "w", stdout);


    cin >> n >> s;

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cin >> t[i][j];
            if (t[i][j] == 'H')
                hives.push_back({ i,j });
            if (t[i][j] == 'M')
                bear = { i,j };
            if (t[i][j] == 'D')
                house = { i,j };
        }
    }


    action();

    
    int l = 0, r = n * n;
    while (l < r)
    {
        int m = (l + r + 1) / 2;
        if (check(m))
            l = m;
        else
            r = m - 1;
    }

    cout << l << '\n';




    return 0;
}

# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Incorrect 1 ms 2396 KB Output isn't correct
3 Incorrect 1 ms 2392 KB Output isn't correct
4 Incorrect 1 ms 2392 KB Output isn't correct
5 Correct 1 ms 2396 KB Output is correct
6 Incorrect 1 ms 2396 KB Output isn't correct
7 Incorrect 103 ms 11008 KB Output isn't correct
8 Incorrect 1 ms 2392 KB Output isn't correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Incorrect 1 ms 4560 KB Output isn't correct
13 Incorrect 1 ms 2652 KB Output isn't correct
14 Incorrect 1 ms 2652 KB Output isn't correct
15 Incorrect 1 ms 2424 KB Output isn't correct
16 Correct 1 ms 2396 KB Output is correct
17 Incorrect 1 ms 2396 KB Output isn't correct
18 Correct 1 ms 2396 KB Output is correct
19 Incorrect 1 ms 2396 KB Output isn't correct
20 Correct 1 ms 2396 KB Output is correct
21 Incorrect 1 ms 2652 KB Output isn't correct
22 Correct 1 ms 2652 KB Output is correct
23 Incorrect 1 ms 2652 KB Output isn't correct
24 Correct 1 ms 4700 KB Output is correct
25 Incorrect 1 ms 2652 KB Output isn't correct
26 Correct 1 ms 4696 KB Output is correct
27 Incorrect 1 ms 2652 KB Output isn't correct
28 Correct 1 ms 4700 KB Output is correct
29 Incorrect 1 ms 2648 KB Output isn't correct
30 Correct 1 ms 4700 KB Output is correct
31 Incorrect 1 ms 2652 KB Output isn't correct
32 Correct 1 ms 4700 KB Output is correct
33 Incorrect 9 ms 5320 KB Output isn't correct
34 Correct 8 ms 5888 KB Output is correct
35 Correct 22 ms 5052 KB Output is correct
36 Incorrect 11 ms 5688 KB Output isn't correct
37 Correct 11 ms 6344 KB Output is correct
38 Correct 30 ms 5664 KB Output is correct
39 Incorrect 14 ms 6308 KB Output isn't correct
40 Correct 14 ms 6760 KB Output is correct
41 Correct 44 ms 6276 KB Output is correct
42 Incorrect 17 ms 6980 KB Output isn't correct
43 Correct 17 ms 7240 KB Output is correct
44 Correct 53 ms 6952 KB Output is correct
45 Incorrect 20 ms 7692 KB Output isn't correct
46 Correct 21 ms 7728 KB Output is correct
47 Correct 77 ms 7700 KB Output is correct
48 Incorrect 24 ms 8336 KB Output isn't correct
49 Correct 24 ms 8408 KB Output is correct
50 Correct 86 ms 8496 KB Output is correct
51 Incorrect 29 ms 8976 KB Output isn't correct
52 Correct 29 ms 8956 KB Output is correct
53 Correct 79 ms 8900 KB Output is correct
54 Incorrect 33 ms 9544 KB Output isn't correct
55 Correct 33 ms 9584 KB Output is correct
56 Correct 94 ms 9552 KB Output is correct
57 Incorrect 37 ms 10300 KB Output isn't correct
58 Correct 39 ms 10300 KB Output is correct
59 Correct 116 ms 10220 KB Output is correct
60 Incorrect 44 ms 11064 KB Output isn't correct
61 Correct 45 ms 11044 KB Output is correct
62 Correct 145 ms 11120 KB Output is correct
63 Correct 103 ms 10992 KB Output is correct
64 Correct 182 ms 11012 KB Output is correct
65 Correct 146 ms 11408 KB Output is correct
66 Incorrect 137 ms 10996 KB Output isn't correct
67 Incorrect 122 ms 10996 KB Output isn't correct
68 Correct 57 ms 11016 KB Output is correct
69 Correct 49 ms 10980 KB Output is correct
70 Correct 49 ms 10984 KB Output is correct
71 Correct 47 ms 10996 KB Output is correct
72 Incorrect 44 ms 11000 KB Output isn't correct
73 Incorrect 43 ms 11032 KB Output isn't correct
74 Correct 68 ms 11044 KB Output is correct
75 Correct 91 ms 11060 KB Output is correct
76 Correct 101 ms 11028 KB Output is correct
77 Correct 77 ms 11036 KB Output is correct
78 Incorrect 78 ms 11016 KB Output isn't correct
79 Correct 57 ms 10960 KB Output is correct
80 Correct 65 ms 10976 KB Output is correct
81 Correct 71 ms 10980 KB Output is correct
82 Correct 64 ms 11008 KB Output is correct
83 Correct 84 ms 11024 KB Output is correct
84 Correct 84 ms 10996 KB Output is correct
85 Correct 87 ms 11004 KB Output is correct
86 Correct 118 ms 11072 KB Output is correct
87 Correct 87 ms 10992 KB Output is correct
88 Correct 89 ms 10972 KB Output is correct
89 Correct 117 ms 10964 KB Output is correct
90 Correct 108 ms 11004 KB Output is correct
91 Correct 92 ms 11000 KB Output is correct
92 Correct 98 ms 11008 KB Output is correct