Submission #995029

# Submission time Handle Problem Language Result Execution time Memory
995029 2024-06-08T11:02:39 Z maomao90 Airline Route Map (JOI18_airline) C++17
37 / 100
355 ms 46356 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> 
#include "Alicelib.h"
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return b < a ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}

typedef unsigned long long ull;
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 SZ(_a) (int) _a.size()
#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

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 1100;

namespace {
    int n, m;
    bool g[MAXN][MAXN], h[MAXN][MAXN];

    inline void add(int u, int v) {
        h[u][v] = h[v][u] = 1;
    }
    inline void answer() {
        vii eg;
        REP (i, 0, m) {
            REP (j, i + 1, m) {
                if (h[i][j]) {
                    eg.pb({i, j});
                }
            }
        }
        InitG(m, SZ(eg));
        REP (i, 0, SZ(eg)) {
            MakeG(i, eg[i].FI, eg[i].SE);
        }
    }
}

void Alice(int N, int E, int A[], int B[]) {
    n = N;
    REP (i, 0, E) {
        g[A[i]][B[i]] = g[B[i]][A[i]] = 1;
    }
    REP (i, 0, n) {
        REP (j, 0, n) {
            h[i][j] = g[i][j];
        }
    }
    if (n <= 2) {
        m = n;
        answer();
        return;
    }
    int lg = 32 - __builtin_clz(n - 1);
    m = n + min(lg + 3, 12);
    REP (l, 0, lg) {
        REP (i, 0, n) {
            if (i >> l & 1) {
                add(n + l, i);
            }
        }
        if (l) {
            add(n + l, n + l - 1);
        }
    }
    if (lg == 10) {
        REP (i, n, n + lg + 1) {
            add(n + lg, i);
        }
        REP (i, 0, n + lg) {
            add(n + lg + 1, i);
        }
    } else {
        add(n + lg, n + lg - 1);
        REP (i, n, n + lg + 1) {
            add(n + lg + 1, i);
        }
        REP (i, 0, n + lg + 1) {
            add(n + lg + 2, i);
        }
    }
    answer();
}
// 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> 
#include "Boblib.h"
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return b < a ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}

typedef unsigned long long ull;
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 SZ(_a) (int) _a.size()
#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

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 1100;

namespace {
    int n, m;
    bool g[MAXN][MAXN], h[MAXN][MAXN];

    inline void add(int u, int v) {
        h[u][v] = h[v][u] = 1;
    }

    int deg[MAXN];
    bool isb[MAXN], vis[MAXN];
    int id[MAXN];
    inline bool rmv(int u, int v) {
        if (!g[u][v]) {
            return 0;
        }
        g[u][v] = g[v][u] = 0;
        deg[u]--; deg[v]--;
        return 1;
    }
    inline void answer() {
        vii eg;
        REP (i, 0, m) {
            REP (j, i + 1, m) {
                if (h[i][j]) {
                    eg.pb({i, j});
                }
            }
        }
        InitMap(m, SZ(eg));
        REP (i, 0, SZ(eg)) {
            MakeMap(eg[i].FI, eg[i].SE);
        }
    }
}

void Bob(int V, int U, int C[], int D[]) {
    REP (i, 0, U) {
        g[C[i]][D[i]] = g[D[i]][C[i]] = 1;
    }
    n = V;
    if (n <= 2) {
        m = n;
        REP (i, 0, n) {
            REP (j, 0, n) {
                h[i][j] = g[i][j];
            }
        }
        answer();
        return;
    }
    REP (x, 1, MAXN) {
        int lg = 32 - __builtin_clz(x - 1);
        if (x + min(12, lg + 3) == n) {
            m = x;
            break;
        }
    }
    assert(m);
    int lg = 32 - __builtin_clz(m - 1);
    ii mx = {0, 0};
    REP (i, 0, n) {
        REP (j, 0, n) {
            deg[i] += g[i][j];
        }
        mxto(mx, {deg[i], i});
    }
    assert(mx.FI == n - 2);
    int r = -1;
    REP (i, 0, n) {
        if (i == mx.SE) {
            continue;
        }
        if (!rmv(mx.SE, i)) {
            assert(r == -1);
            r = i;
        }
    }
    assert(deg[r] == lg + 1);
    REP (i, 0, n) {
        isb[i] = rmv(r, i);
    }
    vi bits;
    if (lg == 10) {
        ii mn = {INF, INF};
        REP (i, 0, n) {
            if (!isb[i]) {
                continue;
            }
            int bdeg = 0;
            REP (j, 0, n) {
                bdeg += isb[j] && g[i][j];
            }
            if (bdeg == 1) {
                mnto(mn, {deg[i], i});
            }
        }
        assert(mn.SE != INF);
        bits.pb(mn.SE);
        vis[mn.SE] = 1;
    } else {
        int e = -1;
        REP (i, 0, n) {
            if (isb[i] && deg[i] == 1) {
                REP (j, 0, n) {
                    if (isb[j] && g[i][j]) {
                        e = i;
                        break;
                    }
                }
                if (e != -1) {
                    break;
                }
            }
        }
        assert(e != -1);
        assert(deg[e] == 1);
        REP (i, 0, n) {
            if (rmv(e, i)) {
                bits.pb(i);
                vis[i] = 1;
            }
        }
    }
    while (SZ(bits) < lg) {
        REP (i, 0, n) {
            if (vis[i] || !isb[i]) {
                continue;
            }
            if (rmv(bits.back(), i)) {
                vis[i] = 1;
                bits.pb(i);
                break;
            }
        }
    }
    reverse(ALL(bits));
    REP (l, 0, lg) {
        REP (i, 0, n) {
            id[i] |= rmv(bits[l], i) << l;
        }
    }
    REP (i, 0, n) {
        REP (j, 0, n) {
            if (g[i][j]) {
                assert(id[i] < m && id[j] < m);
                add(id[i], id[j]);
            }
        }
    }
    answer();
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 19716 KB Output is correct
2 Correct 3 ms 19716 KB Output is correct
3 Correct 2 ms 19724 KB Output is correct
4 Correct 2 ms 17676 KB Output is correct
5 Correct 2 ms 19716 KB Output is correct
6 Correct 3 ms 19716 KB Output is correct
7 Correct 2 ms 19716 KB Output is correct
8 Correct 2 ms 19716 KB Output is correct
9 Correct 3 ms 19720 KB Output is correct
10 Correct 2 ms 17668 KB Output is correct
11 Correct 3 ms 19712 KB Output is correct
12 Correct 3 ms 19716 KB Output is correct
13 Correct 2 ms 19728 KB Output is correct
14 Correct 3 ms 19716 KB Output is correct
15 Correct 3 ms 19716 KB Output is correct
16 Correct 3 ms 19716 KB Output is correct
17 Correct 4 ms 19716 KB Output is correct
18 Correct 3 ms 19716 KB Output is correct
19 Correct 3 ms 19716 KB Output is correct
20 Correct 3 ms 19720 KB Output is correct
21 Correct 3 ms 19716 KB Output is correct
22 Correct 3 ms 19716 KB Output is correct
23 Correct 3 ms 19712 KB Output is correct
24 Correct 2 ms 17668 KB Output is correct
25 Correct 3 ms 19712 KB Output is correct
26 Correct 3 ms 19712 KB Output is correct
27 Correct 3 ms 19716 KB Output is correct
28 Correct 2 ms 19716 KB Output is correct
29 Correct 2 ms 19712 KB Output is correct
30 Correct 2 ms 17668 KB Output is correct
31 Correct 2 ms 17668 KB Output is correct
32 Correct 3 ms 17668 KB Output is correct
33 Correct 2 ms 17668 KB Output is correct
34 Correct 2 ms 17500 KB Output is correct
35 Correct 2 ms 17664 KB Output is correct
36 Correct 3 ms 19724 KB Output is correct
37 Correct 2 ms 19716 KB Output is correct
38 Correct 2 ms 19712 KB Output is correct
39 Correct 3 ms 19716 KB Output is correct
40 Correct 3 ms 19716 KB Output is correct
41 Correct 3 ms 19712 KB Output is correct
42 Correct 3 ms 19712 KB Output is correct
43 Correct 3 ms 19720 KB Output is correct
44 Correct 2 ms 17668 KB Output is correct
45 Correct 2 ms 17676 KB Output is correct
46 Correct 3 ms 19720 KB Output is correct
47 Correct 2 ms 19712 KB Output is correct
48 Correct 2 ms 19712 KB Output is correct
49 Correct 3 ms 19720 KB Output is correct
50 Correct 2 ms 17668 KB Output is correct
51 Correct 2 ms 13572 KB Output is correct
52 Correct 3 ms 19712 KB Output is correct
53 Correct 2 ms 13572 KB Output is correct
54 Correct 2 ms 19716 KB Output is correct
55 Correct 3 ms 19716 KB Output is correct
56 Correct 3 ms 19716 KB Output is correct
57 Correct 3 ms 19712 KB Output is correct
58 Correct 3 ms 19724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 19716 KB Output is correct
2 Correct 3 ms 19716 KB Output is correct
3 Correct 2 ms 19724 KB Output is correct
4 Correct 2 ms 17676 KB Output is correct
5 Correct 2 ms 19716 KB Output is correct
6 Correct 3 ms 19716 KB Output is correct
7 Correct 2 ms 19716 KB Output is correct
8 Correct 2 ms 19716 KB Output is correct
9 Correct 3 ms 19720 KB Output is correct
10 Correct 2 ms 17668 KB Output is correct
11 Correct 3 ms 19712 KB Output is correct
12 Correct 3 ms 19716 KB Output is correct
13 Correct 2 ms 19728 KB Output is correct
14 Correct 3 ms 19716 KB Output is correct
15 Correct 3 ms 19716 KB Output is correct
16 Correct 3 ms 19716 KB Output is correct
17 Correct 4 ms 19716 KB Output is correct
18 Correct 3 ms 19716 KB Output is correct
19 Correct 3 ms 19716 KB Output is correct
20 Correct 3 ms 19720 KB Output is correct
21 Correct 3 ms 19716 KB Output is correct
22 Correct 3 ms 19716 KB Output is correct
23 Correct 3 ms 19712 KB Output is correct
24 Correct 2 ms 17668 KB Output is correct
25 Correct 3 ms 19712 KB Output is correct
26 Correct 3 ms 19712 KB Output is correct
27 Correct 3 ms 19716 KB Output is correct
28 Correct 2 ms 19716 KB Output is correct
29 Correct 2 ms 19712 KB Output is correct
30 Correct 2 ms 17668 KB Output is correct
31 Correct 2 ms 17668 KB Output is correct
32 Correct 3 ms 17668 KB Output is correct
33 Correct 2 ms 17668 KB Output is correct
34 Correct 2 ms 17500 KB Output is correct
35 Correct 2 ms 17664 KB Output is correct
36 Correct 3 ms 19724 KB Output is correct
37 Correct 2 ms 19716 KB Output is correct
38 Correct 2 ms 19712 KB Output is correct
39 Correct 3 ms 19716 KB Output is correct
40 Correct 3 ms 19716 KB Output is correct
41 Correct 3 ms 19712 KB Output is correct
42 Correct 3 ms 19712 KB Output is correct
43 Correct 3 ms 19720 KB Output is correct
44 Correct 2 ms 17668 KB Output is correct
45 Correct 2 ms 17676 KB Output is correct
46 Correct 3 ms 19720 KB Output is correct
47 Correct 2 ms 19712 KB Output is correct
48 Correct 2 ms 19712 KB Output is correct
49 Correct 3 ms 19720 KB Output is correct
50 Correct 2 ms 17668 KB Output is correct
51 Correct 2 ms 13572 KB Output is correct
52 Correct 3 ms 19712 KB Output is correct
53 Correct 2 ms 13572 KB Output is correct
54 Correct 2 ms 19716 KB Output is correct
55 Correct 3 ms 19716 KB Output is correct
56 Correct 3 ms 19716 KB Output is correct
57 Correct 3 ms 19712 KB Output is correct
58 Correct 3 ms 19724 KB Output is correct
59 Correct 3 ms 19716 KB Output is correct
60 Correct 3 ms 19964 KB Output is correct
61 Correct 3 ms 19716 KB Output is correct
62 Correct 3 ms 19724 KB Output is correct
63 Correct 2 ms 19716 KB Output is correct
64 Correct 3 ms 19712 KB Output is correct
65 Correct 3 ms 19716 KB Output is correct
66 Correct 3 ms 19712 KB Output is correct
67 Correct 3 ms 19716 KB Output is correct
68 Correct 2 ms 19716 KB Output is correct
69 Correct 3 ms 19716 KB Output is correct
70 Correct 2 ms 19712 KB Output is correct
71 Correct 3 ms 19716 KB Output is correct
72 Correct 3 ms 19712 KB Output is correct
73 Correct 3 ms 19728 KB Output is correct
74 Correct 2 ms 19712 KB Output is correct
75 Correct 3 ms 19716 KB Output is correct
76 Correct 3 ms 19716 KB Output is correct
77 Correct 3 ms 19712 KB Output is correct
78 Correct 3 ms 19712 KB Output is correct
79 Correct 3 ms 19712 KB Output is correct
80 Correct 3 ms 19720 KB Output is correct
81 Correct 2 ms 19716 KB Output is correct
82 Correct 3 ms 19724 KB Output is correct
83 Correct 2 ms 19720 KB Output is correct
84 Correct 2 ms 19632 KB Output is correct
85 Correct 3 ms 19724 KB Output is correct
86 Correct 3 ms 19712 KB Output is correct
87 Correct 3 ms 19716 KB Output is correct
88 Correct 3 ms 19716 KB Output is correct
89 Correct 2 ms 17664 KB Output is correct
90 Correct 2 ms 17664 KB Output is correct
91 Correct 2 ms 17668 KB Output is correct
92 Correct 2 ms 17668 KB Output is correct
93 Correct 2 ms 17664 KB Output is correct
94 Correct 3 ms 19716 KB Output is correct
95 Correct 3 ms 19716 KB Output is correct
96 Correct 3 ms 19716 KB Output is correct
97 Correct 3 ms 19716 KB Output is correct
98 Correct 3 ms 19716 KB Output is correct
99 Correct 3 ms 19716 KB Output is correct
100 Correct 2 ms 19716 KB Output is correct
101 Correct 3 ms 19708 KB Output is correct
102 Correct 3 ms 17668 KB Output is correct
103 Correct 2 ms 19716 KB Output is correct
104 Correct 3 ms 19716 KB Output is correct
105 Correct 3 ms 19708 KB Output is correct
106 Correct 3 ms 19716 KB Output is correct
107 Correct 3 ms 19716 KB Output is correct
108 Correct 3 ms 19712 KB Output is correct
109 Correct 3 ms 19716 KB Output is correct
110 Correct 3 ms 19716 KB Output is correct
111 Correct 3 ms 19716 KB Output is correct
112 Correct 3 ms 19724 KB Output is correct
113 Correct 3 ms 19716 KB Output is correct
114 Correct 3 ms 19712 KB Output is correct
115 Correct 3 ms 19744 KB Output is correct
116 Correct 3 ms 19716 KB Output is correct
117 Correct 3 ms 19716 KB Output is correct
118 Correct 2 ms 19744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 355 ms 46356 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -