Submission #556360

# Submission time Handle Problem Language Result Execution time Memory
556360 2022-05-03T03:22:54 Z maomao90 Highway Tolls (IOI18_highway) C++17
100 / 100
226 ms 16492 KB
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
using namespace std;
#include "highway.h"

template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

#define INF 1000000005
#define LINF 1000000000000000005ll
#define MAXN 200005

int n, m;
ii eg[MAXN];
vii adj[MAXN];
int a, b;
ll itoll;
vi w;
ii p[MAXN];
int dis[MAXN], comp[MAXN];
bool back[MAXN];

void find_pair(int N, vi U, vi V, int A, int B) {
    n = N, m = U.size();
    a = A, b = B;
    REP (i, 0, m) {
        adj[U[i]].pb({V[i], i});
        adj[V[i]].pb({U[i], i});
        eg[i] = {U[i], V[i]};
    }
    w = vi(m, 0);
    itoll = ask(w);
    REP (i, 0, m) {
        back[i] = 1;
    }
    int sl = -1, tl;
    {
        int lo = 0, hi = m - 1, mid;
        while (lo < hi) {
            mid = lo + hi >> 1;
            w = vi(m, 0);
            REP (i, 0, mid + 1) {
                w[i] = 1;
            }
            ll toll = ask(w);
            if (toll != itoll) {
                hi = mid;
            } else {
                lo = mid + 1;
            }
        }
        tie(sl, tl) = eg[lo];
        back[lo] = 0;
    }
    assert(sl != -1);
    cerr << sl << ' ' << tl << '\n';
    queue<int> q;
    memset(comp, -1, sizeof comp);
    REP (i, 0, n) {
        dis[i] = INF;
    }
    dis[sl] = 0;
    comp[sl] = sl;
    q.push(sl);
    dis[tl] = 0;
    comp[tl] = tl;
    q.push(tl);
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (auto [v, i] : adj[u]) {
            if (mnto(dis[v], dis[u] + 1)) {
                back[i] = 0;
                q.push(v);
                p[v] = {u, i};
                comp[v] = comp[u];
            }
        }
    }
    REP (i, 0, m) {
        if (dis[eg[i].FI] < dis[eg[i].SE]) {
            swap(eg[i].FI, eg[i].SE);
        }
        if (back[i]) {
            cerr << "back " << i << '\n';
        }
    }
    int s = -1, t = -1;
    REP (z, 0, 2) {
        vi pot;
        REP (i, 0, n) {
            if (i != sl && comp[i] == sl) {
                pot.pb(i);
            }
        }
        sort(ALL(pot), [&] (int l, int r) {
                return dis[l] < dis[r];
                });
        cerr << sl << '\n';
        for (int i : pot) {
            cerr << "  " << i;
        }
        cerr << '\n';
        {
            int lo = -1, hi = pot.size() - 1, mid;
            while (lo < hi) {
                w = vi(m, 0);
                int mid = lo + hi == -1 ? -1 : lo + hi >> 1;
                REP (i, mid + 1, pot.size()) {
                    w[p[pot[i]].SE] = 1;
                }
                REP (i, 0, m) {
                    if (back[i]) {
                        w[i] = 1;
                    }
                }
                cerr << lo << ' ' << hi << ' ' << mid << '\n';
                REP (i, 0, m) {
                    cerr << "   " << w[i];
                }
                cerr << '\n';
                ll toll = ask(w);
                if (toll == itoll) {
                    hi = mid;
                } else {
                    lo = mid + 1;
                }
            }
            if (hi == -1) {
                s = sl;
            } else {
                cerr << "   !" << p[pot[hi]].FI << '\n';
                s = eg[p[pot[hi]].SE].FI;
            }
            cerr << ' ' << hi << ' ' << s << '\n';
        }
        assert(s != -1);
        swap(s, t);
        swap(sl, tl);
    }
    answer(s, t);
    cerr << s << ' ' << t << '\n';
}

Compilation message

highway.cpp: In function 'void find_pair(int, vi, vi, int, int)':
highway.cpp:65:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   65 |             mid = lo + hi >> 1;
      |                   ~~~^~~~
highway.cpp:132:51: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  132 |                 int mid = lo + hi == -1 ? -1 : lo + hi >> 1;
      |                                                ~~~^~~~
highway.cpp:14:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 | #define REP(i, s, e) for (int i = s; i < e; i++)
......
  133 |                 REP (i, mid + 1, pot.size()) {
      |                      ~~~~~~~~~~~~~~~~~~~~~~
highway.cpp:133:17: note: in expansion of macro 'REP'
  133 |                 REP (i, mid + 1, pot.size()) {
      |                 ^~~
highway.cpp:129:47: warning: unused variable 'mid' [-Wunused-variable]
  129 |             int lo = -1, hi = pot.size() - 1, mid;
      |                                               ^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 3 ms 5712 KB Output is correct
4 Correct 3 ms 5712 KB Output is correct
5 Correct 3 ms 5712 KB Output is correct
6 Correct 3 ms 5712 KB Output is correct
7 Correct 3 ms 5784 KB Output is correct
8 Correct 3 ms 5780 KB Output is correct
9 Correct 3 ms 5712 KB Output is correct
10 Correct 3 ms 5712 KB Output is correct
11 Correct 3 ms 5712 KB Output is correct
12 Correct 3 ms 5712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5840 KB Output is correct
2 Correct 14 ms 6608 KB Output is correct
3 Correct 123 ms 13836 KB Output is correct
4 Correct 134 ms 13780 KB Output is correct
5 Correct 125 ms 13680 KB Output is correct
6 Correct 140 ms 13856 KB Output is correct
7 Correct 129 ms 13712 KB Output is correct
8 Correct 124 ms 13684 KB Output is correct
9 Correct 114 ms 13928 KB Output is correct
10 Correct 121 ms 13672 KB Output is correct
11 Correct 177 ms 13164 KB Output is correct
12 Correct 177 ms 13176 KB Output is correct
13 Correct 140 ms 13092 KB Output is correct
14 Correct 141 ms 13176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 6592 KB Output is correct
2 Correct 23 ms 7424 KB Output is correct
3 Correct 32 ms 8432 KB Output is correct
4 Correct 95 ms 13052 KB Output is correct
5 Correct 91 ms 13128 KB Output is correct
6 Correct 90 ms 13036 KB Output is correct
7 Correct 99 ms 13088 KB Output is correct
8 Correct 103 ms 13204 KB Output is correct
9 Correct 95 ms 13012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5848 KB Output is correct
2 Correct 15 ms 6596 KB Output is correct
3 Correct 91 ms 12112 KB Output is correct
4 Correct 154 ms 13672 KB Output is correct
5 Correct 118 ms 13860 KB Output is correct
6 Correct 116 ms 13928 KB Output is correct
7 Correct 120 ms 13732 KB Output is correct
8 Correct 119 ms 13668 KB Output is correct
9 Correct 128 ms 13652 KB Output is correct
10 Correct 128 ms 13776 KB Output is correct
11 Correct 135 ms 13348 KB Output is correct
12 Correct 127 ms 13180 KB Output is correct
13 Correct 147 ms 13036 KB Output is correct
14 Correct 147 ms 13288 KB Output is correct
15 Correct 119 ms 13704 KB Output is correct
16 Correct 116 ms 13860 KB Output is correct
17 Correct 141 ms 13160 KB Output is correct
18 Correct 152 ms 13240 KB Output is correct
19 Correct 112 ms 14032 KB Output is correct
20 Correct 135 ms 13188 KB Output is correct
21 Correct 96 ms 14292 KB Output is correct
22 Correct 104 ms 14296 KB Output is correct
23 Correct 111 ms 13868 KB Output is correct
24 Correct 118 ms 13760 KB Output is correct
25 Correct 139 ms 13432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 6688 KB Output is correct
2 Correct 18 ms 6844 KB Output is correct
3 Correct 144 ms 14152 KB Output is correct
4 Correct 163 ms 14904 KB Output is correct
5 Correct 189 ms 16460 KB Output is correct
6 Correct 226 ms 16232 KB Output is correct
7 Correct 195 ms 16228 KB Output is correct
8 Correct 196 ms 16160 KB Output is correct
9 Correct 126 ms 13744 KB Output is correct
10 Correct 126 ms 14316 KB Output is correct
11 Correct 128 ms 14604 KB Output is correct
12 Correct 186 ms 15596 KB Output is correct
13 Correct 197 ms 16024 KB Output is correct
14 Correct 217 ms 16192 KB Output is correct
15 Correct 204 ms 16112 KB Output is correct
16 Correct 174 ms 14764 KB Output is correct
17 Correct 131 ms 14092 KB Output is correct
18 Correct 121 ms 14244 KB Output is correct
19 Correct 114 ms 14180 KB Output is correct
20 Correct 110 ms 14276 KB Output is correct
21 Correct 205 ms 15920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 6652 KB Output is correct
2 Correct 18 ms 6728 KB Output is correct
3 Correct 163 ms 14400 KB Output is correct
4 Correct 158 ms 14428 KB Output is correct
5 Correct 179 ms 14928 KB Output is correct
6 Correct 196 ms 16112 KB Output is correct
7 Correct 125 ms 14328 KB Output is correct
8 Correct 175 ms 14520 KB Output is correct
9 Correct 166 ms 14728 KB Output is correct
10 Correct 192 ms 16052 KB Output is correct
11 Correct 201 ms 16212 KB Output is correct
12 Correct 187 ms 16136 KB Output is correct
13 Correct 141 ms 14920 KB Output is correct
14 Correct 137 ms 14196 KB Output is correct
15 Correct 136 ms 14456 KB Output is correct
16 Correct 132 ms 14196 KB Output is correct
17 Correct 142 ms 14464 KB Output is correct
18 Correct 125 ms 14456 KB Output is correct
19 Correct 188 ms 15628 KB Output is correct
20 Correct 187 ms 15864 KB Output is correct
21 Correct 193 ms 16208 KB Output is correct
22 Correct 208 ms 16108 KB Output is correct
23 Correct 204 ms 16252 KB Output is correct
24 Correct 213 ms 16340 KB Output is correct
25 Correct 210 ms 16132 KB Output is correct
26 Correct 198 ms 16084 KB Output is correct
27 Correct 108 ms 14308 KB Output is correct
28 Correct 108 ms 14108 KB Output is correct
29 Correct 104 ms 14512 KB Output is correct
30 Correct 100 ms 14256 KB Output is correct
31 Correct 110 ms 14188 KB Output is correct
32 Correct 116 ms 14100 KB Output is correct
33 Correct 113 ms 14348 KB Output is correct
34 Correct 114 ms 14284 KB Output is correct
35 Correct 103 ms 14140 KB Output is correct
36 Correct 112 ms 14064 KB Output is correct
37 Correct 108 ms 14300 KB Output is correct
38 Correct 114 ms 14324 KB Output is correct
39 Correct 213 ms 16492 KB Output is correct
40 Correct 211 ms 16240 KB Output is correct
41 Correct 182 ms 15848 KB Output is correct
42 Correct 222 ms 16212 KB Output is correct