Submission #598325

# Submission time Handle Problem Language Result Execution time Memory
598325 2022-07-18T04:27:42 Z Hanksburger Mecho (IOI09_mecho) C++17
84 / 100
362 ms 39184 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=640000;
    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);
            }
        }
        d[i]=1e9;
    }
    for (int u:bee)
    {
        d[u]=0;
        b[u]=1;
        q.push(u);
    }
    while (!q.empty())
    {
        int u=q.front();
        q.pop();
        for (int v:adj[u])
        {
            if (!b[v])
            {
                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:67:13: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
   67 |         b[s]=1;
      |         ~~~~^~
mecho.cpp:75:17: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
   75 |                 if (v==e)
      |                 ^~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 15316 KB Output is correct
2 Correct 9 ms 15348 KB Output is correct
3 Correct 9 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 279 ms 39176 KB Output is correct
8 Correct 8 ms 15316 KB Output is correct
9 Correct 9 ms 15316 KB Output is correct
10 Correct 8 ms 15376 KB Output is correct
11 Correct 8 ms 15316 KB Output is correct
12 Incorrect 9 ms 15444 KB Output isn't correct
13 Incorrect 9 ms 15444 KB Output isn't correct
14 Correct 9 ms 15444 KB Output is correct
15 Correct 10 ms 15372 KB Output is correct
16 Correct 9 ms 15316 KB Output is correct
17 Correct 10 ms 15328 KB Output is correct
18 Correct 9 ms 15316 KB Output is correct
19 Correct 8 ms 15304 KB Output is correct
20 Correct 8 ms 15316 KB Output is correct
21 Correct 8 ms 15316 KB Output is correct
22 Correct 8 ms 15316 KB Output is correct
23 Correct 8 ms 15316 KB Output is correct
24 Correct 10 ms 15316 KB Output is correct
25 Correct 8 ms 15408 KB Output is correct
26 Correct 9 ms 15452 KB Output is correct
27 Correct 9 ms 15468 KB Output is correct
28 Correct 9 ms 15444 KB Output is correct
29 Correct 8 ms 15480 KB Output is correct
30 Correct 8 ms 15444 KB Output is correct
31 Correct 8 ms 15444 KB Output is correct
32 Correct 9 ms 15444 KB Output is correct
33 Correct 17 ms 17996 KB Output is correct
34 Correct 18 ms 18004 KB Output is correct
35 Correct 60 ms 18868 KB Output is correct
36 Correct 21 ms 18772 KB Output is correct
37 Correct 19 ms 18772 KB Output is correct
38 Correct 61 ms 20044 KB Output is correct
39 Correct 21 ms 19668 KB Output is correct
40 Correct 22 ms 19668 KB Output is correct
41 Correct 97 ms 21228 KB Output is correct
42 Correct 26 ms 20648 KB Output is correct
43 Correct 25 ms 20716 KB Output is correct
44 Correct 115 ms 22604 KB Output is correct
45 Correct 28 ms 21800 KB Output is correct
46 Correct 27 ms 21892 KB Output is correct
47 Correct 155 ms 24224 KB Output is correct
48 Correct 30 ms 23112 KB Output is correct
49 Correct 31 ms 23124 KB Output is correct
50 Correct 181 ms 25900 KB Output is correct
51 Correct 35 ms 24348 KB Output is correct
52 Correct 35 ms 24412 KB Output is correct
53 Correct 227 ms 27684 KB Output is correct
54 Correct 37 ms 25804 KB Output is correct
55 Correct 45 ms 25808 KB Output is correct
56 Correct 247 ms 29720 KB Output is correct
57 Correct 49 ms 27352 KB Output is correct
58 Correct 44 ms 27440 KB Output is correct
59 Correct 332 ms 31836 KB Output is correct
60 Correct 49 ms 29128 KB Output is correct
61 Correct 49 ms 29032 KB Output is correct
62 Correct 346 ms 34100 KB Output is correct
63 Correct 203 ms 30936 KB Output is correct
64 Correct 362 ms 31060 KB Output is correct
65 Correct 277 ms 31056 KB Output is correct
66 Correct 242 ms 31052 KB Output is correct
67 Correct 229 ms 31132 KB Output is correct
68 Correct 119 ms 30980 KB Output is correct
69 Correct 136 ms 30984 KB Output is correct
70 Correct 108 ms 31076 KB Output is correct
71 Correct 107 ms 31076 KB Output is correct
72 Incorrect 98 ms 31180 KB Output isn't correct
73 Incorrect 185 ms 39088 KB Output isn't correct
74 Correct 202 ms 39044 KB Output is correct
75 Correct 225 ms 39184 KB Output is correct
76 Correct 214 ms 39084 KB Output is correct
77 Correct 227 ms 39092 KB Output is correct
78 Correct 259 ms 39064 KB Output is correct
79 Correct 175 ms 38988 KB Output is correct
80 Correct 204 ms 39080 KB Output is correct
81 Correct 224 ms 39084 KB Output is correct
82 Correct 210 ms 38980 KB Output is correct
83 Correct 260 ms 39012 KB Output is correct
84 Correct 248 ms 39016 KB Output is correct
85 Correct 263 ms 39004 KB Output is correct
86 Correct 261 ms 39008 KB Output is correct
87 Correct 251 ms 39016 KB Output is correct
88 Correct 301 ms 39036 KB Output is correct
89 Correct 278 ms 39104 KB Output is correct
90 Correct 272 ms 39020 KB Output is correct
91 Correct 267 ms 39036 KB Output is correct
92 Correct 280 ms 39084 KB Output is correct