Submission #598326

# Submission time Handle Problem Language Result Execution time Memory
598326 2022-07-18T04:35:22 Z Hanksburger Mecho (IOI09_mecho) C++17
84 / 100
353 ms 39140 KB
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[640005], bee;
queue<pair<int, int> > qq;
char a[640005];
bool b[640005];
int d[640005];
queue<int> q;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, p, s, e, l=-1, r=1e6;
    cin >> n >> p;
    for (int i=0; i<n*n; i++)
    {
        cin >> a[i];
        if (a[i]=='M')
            s=i;
        else if (a[i]=='D')
            e=i;
        else if (a[i]=='H')
            bee.push_back(i);
        if (a[i]!='T')
        {
            a[i]='G';
            if (i>=n && a[i-n]=='G')
            {
                adj[i].push_back(i-n);
                adj[i-n].push_back(i);
            }
            if (i%n && a[i-1]=='G')
            {
                adj[i].push_back(i-1);
                adj[i-1].push_back(i);
            }
        }
    }
    for (int u:bee)
    {
        b[u]=1;
        q.push(u);
    }
    while (!q.empty())
    {
        int u=q.front();
        q.pop();
        for (int v:adj[u])
        {
            if (!b[v] && v!=e)
            {
                d[v]=d[u]+1;
                b[v]=1;
                q.push(v);
            }
        }
    }
    while (l<r)
    {
        int m=(l+r+1)/2;
        for (int i=0; i<n*n; i++)
            b[i]=0;
        qq.push({s, 0});
        b[s]=1;
        bool ok=0;
        while (!qq.empty())
        {
            int u=qq.front().first, w=qq.front().second;
            qq.pop();
            for (int v:adj[u])
            {
                if (v==e)
                {
                    ok=1;
                    break;
                }
                if (!b[v] && w+1<(d[v]-m)*p)
                {
                    b[v]=1;
                    qq.push({v, w+1});
                }
            }
            if (ok)
                while (!qq.empty())
                    qq.pop();
        }
        if (ok)
            l=m;
        else
            r=m-1;
    }
    cout << l;
    return 0;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:65:13: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   65 |         b[s]=1;
      |         ~~~~^~
mecho.cpp:51:23: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
   51 |             if (!b[v] && v!=e)
      |                 ~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15316 KB Output is correct
2 Correct 8 ms 15316 KB Output is correct
3 Correct 8 ms 15316 KB Output is correct
4 Correct 8 ms 15316 KB Output is correct
5 Correct 8 ms 15316 KB Output is correct
6 Correct 7 ms 15316 KB Output is correct
7 Correct 276 ms 39104 KB Output is correct
8 Correct 10 ms 15316 KB Output is correct
9 Correct 8 ms 15336 KB Output is correct
10 Correct 8 ms 15316 KB Output is correct
11 Correct 10 ms 15316 KB Output is correct
12 Incorrect 9 ms 15444 KB Output isn't correct
13 Incorrect 8 ms 15444 KB Output isn't correct
14 Correct 9 ms 15444 KB Output is correct
15 Correct 8 ms 15316 KB Output is correct
16 Correct 8 ms 15316 KB Output is correct
17 Correct 8 ms 15316 KB Output is correct
18 Correct 8 ms 15272 KB Output is correct
19 Correct 8 ms 15372 KB Output is correct
20 Correct 8 ms 15360 KB Output is correct
21 Correct 8 ms 15348 KB Output is correct
22 Correct 8 ms 15316 KB Output is correct
23 Correct 8 ms 15356 KB Output is correct
24 Correct 9 ms 15316 KB Output is correct
25 Correct 9 ms 15456 KB Output is correct
26 Correct 9 ms 15444 KB Output is correct
27 Correct 11 ms 15444 KB Output is correct
28 Correct 10 ms 15444 KB Output is correct
29 Correct 9 ms 15444 KB Output is correct
30 Correct 9 ms 15432 KB Output is correct
31 Correct 8 ms 15504 KB Output is correct
32 Correct 8 ms 15396 KB Output is correct
33 Correct 15 ms 17976 KB Output is correct
34 Correct 17 ms 18004 KB Output is correct
35 Correct 47 ms 18900 KB Output is correct
36 Correct 18 ms 18816 KB Output is correct
37 Correct 23 ms 18764 KB Output is correct
38 Correct 82 ms 20044 KB Output is correct
39 Correct 22 ms 19672 KB Output is correct
40 Correct 21 ms 19724 KB Output is correct
41 Correct 89 ms 21296 KB Output is correct
42 Correct 23 ms 20716 KB Output is correct
43 Correct 26 ms 20616 KB Output is correct
44 Correct 117 ms 22680 KB Output is correct
45 Correct 26 ms 21848 KB Output is correct
46 Correct 29 ms 22000 KB Output is correct
47 Correct 157 ms 24224 KB Output is correct
48 Correct 30 ms 23112 KB Output is correct
49 Correct 37 ms 23048 KB Output is correct
50 Correct 168 ms 25904 KB Output is correct
51 Correct 35 ms 24396 KB Output is correct
52 Correct 43 ms 24344 KB Output is correct
53 Correct 227 ms 27768 KB Output is correct
54 Correct 37 ms 25812 KB Output is correct
55 Correct 39 ms 25828 KB Output is correct
56 Correct 250 ms 29680 KB Output is correct
57 Correct 46 ms 27584 KB Output is correct
58 Correct 46 ms 27476 KB Output is correct
59 Correct 335 ms 31844 KB Output is correct
60 Correct 47 ms 29072 KB Output is correct
61 Correct 47 ms 29048 KB Output is correct
62 Correct 353 ms 34100 KB Output is correct
63 Correct 205 ms 31052 KB Output is correct
64 Correct 299 ms 31164 KB Output is correct
65 Correct 293 ms 31056 KB Output is correct
66 Correct 256 ms 31052 KB Output is correct
67 Correct 218 ms 31056 KB Output is correct
68 Correct 120 ms 31048 KB Output is correct
69 Correct 126 ms 31080 KB Output is correct
70 Correct 123 ms 30976 KB Output is correct
71 Correct 103 ms 31080 KB Output is correct
72 Incorrect 98 ms 31080 KB Output isn't correct
73 Incorrect 164 ms 39004 KB Output isn't correct
74 Correct 215 ms 39092 KB Output is correct
75 Correct 243 ms 39088 KB Output is correct
76 Correct 235 ms 39096 KB Output is correct
77 Correct 223 ms 38988 KB Output is correct
78 Correct 222 ms 39032 KB Output is correct
79 Correct 186 ms 39036 KB Output is correct
80 Correct 213 ms 39048 KB Output is correct
81 Correct 225 ms 39088 KB Output is correct
82 Correct 193 ms 39140 KB Output is correct
83 Correct 251 ms 39008 KB Output is correct
84 Correct 235 ms 38936 KB Output is correct
85 Correct 248 ms 39008 KB Output is correct
86 Correct 264 ms 38912 KB Output is correct
87 Correct 264 ms 39116 KB Output is correct
88 Correct 264 ms 38956 KB Output is correct
89 Correct 267 ms 38972 KB Output is correct
90 Correct 276 ms 39024 KB Output is correct
91 Correct 268 ms 39040 KB Output is correct
92 Correct 274 ms 39020 KB Output is correct