Submission #244270

# Submission time Handle Problem Language Result Execution time Memory
244270 2020-07-03T13:04:29 Z JovanK26 Mecho (IOI09_mecho) C++14
4 / 100
146 ms 5164 KB
#include <bits/stdc++.h>

using namespace std;
int n,s;
bool is[801][801];
int tim[801][801];
bool vis[801][801];
struct field
{
    int x,y;
};
vector<field> hives;
field start;
field home;
bool check(int m)
{
     bool visited[801][801];
     for(int i=0;i<n;i++)
     {
         for(int j=0;j<n;j++)
         {
             visited[i][j]=0;
         }
     }
     if(m>=tim[start.x][start.y])return 0;
     queue<pair<field,int> > q;
     q.push(make_pair(start,0));
     while(!q.empty())
    {
        auto x=q.front();
        q.pop();
        field cur=x.first;
        if(cur.x==home.x && cur.y==home.y)return 1;
        int d=x.second;
        visited[cur.x][cur.y]=1;
        if(cur.x+1<n && !visited[cur.x+1][cur.y] && is[cur.x+1][cur.y] && m+d/s<tim[cur.x+1][cur.y])
        {
            cur.x++;
            visited[cur.x][cur.y]=1;
            q.push(make_pair(cur,d+1));
            cur.x--;
        }
        if(cur.x-1>=0 && !visited[cur.x-1][cur.y] && is[cur.x-1][cur.y] && m+d/s<tim[cur.x-1][cur.y])
        {
            cur.x--;
            visited[cur.x][cur.y]=1;
            q.push(make_pair(cur,d+1));
            cur.x++;
        }
        if(cur.y+1<n && !visited[cur.x][cur.y+1] && is[cur.x][cur.y+1] && m+d/s<tim[cur.x][cur.y+1])
        {
            cur.y++;
            visited[cur.x][cur.y]=1;
            q.push(make_pair(cur,d+1));
            cur.y--;
        }
        if(cur.y-1>=0 && !visited[cur.x][cur.y-1] && is[cur.x][cur.y-1] && m+d/s<tim[cur.x][cur.y-1])
        {
            cur.y--;
            visited[cur.x][cur.y]=1;
            q.push(make_pair(cur,d+1));
            cur.y++;
        }
    }
    return 0;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> s;
    char c;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
           cin >> c;
           if(c=='T')
           {
               is[i][j]=0;
           }
           else if(c=='M')
           {
               is[i][j]=1;
               start.x=i;
               start.y=j;
           }
           else if(c=='D')
           {
               is[i][j]=1;
               home.x=i;
               home.y=j;
           }
           else if(c=='H')
           {
               is[i][j]=1;
               field temp;
               temp.x=i;
               temp.y=j;
               hives.push_back(temp);
           }
           else
           {
               is[i][j]=1;
           }
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            tim[i][j]=1000000000;
        }
    }
    queue<pair<field,int> > q;
    for(int i=0;i<hives.size();i++)
    {
        q.push(make_pair(hives[i],0));
        vis[hives[i].x][hives[i].y]=1;
    }
    while(!q.empty())
    {
        auto x=q.front();
        q.pop();
        field cur=x.first;
        int d=x.second;
        //if(vis[cur.x][cur.y])continue;
        vis[cur.x][cur.y]=1;
        tim[cur.x][cur.y]=min(tim[cur.x][cur.y],d);
        if(cur.x+1<n && !vis[cur.x+1][cur.y] && is[cur.x+1][cur.y])
        {
            cur.x++;
            vis[cur.x][cur.y]=1;
            q.push(make_pair(cur,d+1));
            cur.x--;
        }
        if(cur.x-1>=0 && !vis[cur.x-1][cur.y] && is[cur.x-1][cur.y])
        {
            cur.x--;
            vis[cur.x][cur.y]=1;
            q.push(make_pair(cur,d+1));
            cur.x++;
        }
        if(cur.y+1<n && !vis[cur.x][cur.y+1] && is[cur.x][cur.y+1])
        {
            cur.y++;
            vis[cur.x][cur.y]=1;
            q.push(make_pair(cur,d+1));
            cur.y--;
        }
        if(cur.y-1>=0 && !vis[cur.x][cur.y-1] && is[cur.x][cur.y-1])
        {
            cur.y--;
            vis[cur.x][cur.y]=1;
            q.push(make_pair(cur,d+1));
            cur.y++;
        }
    }
    tim[home.x][home.y]=1000000000;
    int l=0;
    int r=1000000;
    int m;
    int rez=1000000000;
    while(l<r)
    {
        m=(l+r)/2;
        if(check(m))
        {
            l=m+1;
            rez=max(rez,m);
        }
        else
        {
            r=m;
        }
    }
    if(rez==1000000000)rez=-1;
    cout << rez;
    return 0;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:117:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<hives.size();i++)
                 ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 384 KB Output isn't correct
2 Incorrect 4 ms 384 KB Output isn't correct
3 Incorrect 5 ms 384 KB Output isn't correct
4 Incorrect 5 ms 384 KB Output isn't correct
5 Incorrect 4 ms 384 KB Output isn't correct
6 Incorrect 4 ms 384 KB Output isn't correct
7 Incorrect 74 ms 4856 KB Output isn't correct
8 Correct 4 ms 384 KB Output is correct
9 Incorrect 4 ms 384 KB Output isn't correct
10 Incorrect 4 ms 384 KB Output isn't correct
11 Incorrect 5 ms 384 KB Output isn't correct
12 Incorrect 5 ms 640 KB Output isn't correct
13 Incorrect 5 ms 640 KB Output isn't correct
14 Correct 5 ms 640 KB Output is correct
15 Incorrect 5 ms 512 KB Output isn't correct
16 Incorrect 5 ms 512 KB Output isn't correct
17 Incorrect 5 ms 512 KB Output isn't correct
18 Incorrect 5 ms 512 KB Output isn't correct
19 Incorrect 5 ms 512 KB Output isn't correct
20 Incorrect 5 ms 512 KB Output isn't correct
21 Incorrect 7 ms 512 KB Output isn't correct
22 Incorrect 5 ms 512 KB Output isn't correct
23 Incorrect 5 ms 640 KB Output isn't correct
24 Incorrect 5 ms 640 KB Output isn't correct
25 Incorrect 5 ms 640 KB Output isn't correct
26 Incorrect 5 ms 640 KB Output isn't correct
27 Incorrect 5 ms 768 KB Output isn't correct
28 Incorrect 5 ms 640 KB Output isn't correct
29 Incorrect 5 ms 768 KB Output isn't correct
30 Incorrect 5 ms 768 KB Output isn't correct
31 Incorrect 5 ms 768 KB Output isn't correct
32 Incorrect 5 ms 768 KB Output isn't correct
33 Incorrect 10 ms 2312 KB Output isn't correct
34 Incorrect 9 ms 2304 KB Output isn't correct
35 Incorrect 20 ms 2304 KB Output isn't correct
36 Incorrect 11 ms 2560 KB Output isn't correct
37 Incorrect 10 ms 2560 KB Output isn't correct
38 Incorrect 25 ms 2560 KB Output isn't correct
39 Incorrect 13 ms 2816 KB Output isn't correct
40 Incorrect 12 ms 2816 KB Output isn't correct
41 Incorrect 31 ms 2816 KB Output isn't correct
42 Incorrect 14 ms 3072 KB Output isn't correct
43 Incorrect 14 ms 3072 KB Output isn't correct
44 Incorrect 40 ms 3072 KB Output isn't correct
45 Incorrect 17 ms 3328 KB Output isn't correct
46 Incorrect 15 ms 3328 KB Output isn't correct
47 Incorrect 45 ms 3456 KB Output isn't correct
48 Incorrect 19 ms 3584 KB Output isn't correct
49 Incorrect 18 ms 3704 KB Output isn't correct
50 Incorrect 57 ms 3704 KB Output isn't correct
51 Incorrect 21 ms 3968 KB Output isn't correct
52 Incorrect 20 ms 3968 KB Output isn't correct
53 Incorrect 66 ms 3948 KB Output isn't correct
54 Incorrect 23 ms 4224 KB Output isn't correct
55 Incorrect 22 ms 4224 KB Output isn't correct
56 Incorrect 71 ms 4224 KB Output isn't correct
57 Incorrect 26 ms 4480 KB Output isn't correct
58 Incorrect 24 ms 4480 KB Output isn't correct
59 Incorrect 88 ms 4480 KB Output isn't correct
60 Incorrect 30 ms 4736 KB Output isn't correct
61 Incorrect 26 ms 4728 KB Output isn't correct
62 Incorrect 113 ms 4728 KB Output isn't correct
63 Incorrect 100 ms 4728 KB Output isn't correct
64 Incorrect 146 ms 4728 KB Output isn't correct
65 Incorrect 134 ms 4728 KB Output isn't correct
66 Incorrect 139 ms 4728 KB Output isn't correct
67 Correct 116 ms 4728 KB Output is correct
68 Incorrect 62 ms 4776 KB Output isn't correct
69 Incorrect 56 ms 4728 KB Output isn't correct
70 Incorrect 51 ms 4728 KB Output isn't correct
71 Incorrect 42 ms 4732 KB Output isn't correct
72 Incorrect 42 ms 4728 KB Output isn't correct
73 Incorrect 38 ms 5120 KB Output isn't correct
74 Incorrect 56 ms 5120 KB Output isn't correct
75 Incorrect 60 ms 5112 KB Output isn't correct
76 Incorrect 55 ms 5120 KB Output isn't correct
77 Incorrect 57 ms 5112 KB Output isn't correct
78 Correct 67 ms 5112 KB Output is correct
79 Incorrect 55 ms 5112 KB Output isn't correct
80 Incorrect 59 ms 5164 KB Output isn't correct
81 Incorrect 64 ms 5112 KB Output isn't correct
82 Incorrect 57 ms 5112 KB Output isn't correct
83 Incorrect 72 ms 4976 KB Output isn't correct
84 Incorrect 60 ms 4984 KB Output isn't correct
85 Incorrect 64 ms 5104 KB Output isn't correct
86 Incorrect 68 ms 4984 KB Output isn't correct
87 Incorrect 67 ms 4984 KB Output isn't correct
88 Incorrect 71 ms 4984 KB Output isn't correct
89 Incorrect 70 ms 4928 KB Output isn't correct
90 Incorrect 85 ms 4856 KB Output isn't correct
91 Incorrect 83 ms 4984 KB Output isn't correct
92 Incorrect 77 ms 4984 KB Output isn't correct