Submission #783601

# Submission time Handle Problem Language Result Execution time Memory
783601 2023-07-15T05:35:45 Z Magikarp4000 Highway Tolls (IOI18_highway) C++17
51 / 100
173 ms 262144 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int(1e9+7)
#define ln '\n' 
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define PB push_back
#define in(v,x) (v.find(x) != v.end())
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
const ll LLINF = 1e18+1;
#define int long long

struct Edge {
    int x,y,depth;
};

const int MAXN = 9e4+5;
int n,m;
vector<PII> v[MAXN];
vector<int32_t> w, tour;
vector<Edge> e;
int d[MAXN], ans;

void dfs(int s, int pa) {
    FORX(u,v[s]) {
        if (u.F == pa) continue;
        if (e[u.S].y != u.F) swap(e[u.S].x, e[u.S].y);
        tour.PB(u.S);
        dfs(u.F,s);
    }
}

int find_end(int s, int pa) {
    tour.clear();
    dfs(s,pa);
    // FORX(u,tour) cout << u << " ";
    // cout << ln;
    int l = -1, r = tour.size()-1;
    while (l < r) {
        FOR(i,0,m) w[i] = 0;
        int mid = (l+r+1)/2;
        FOR(i,mid,r+1) w[tour[i]] = 1;
        int val = ask(w);
        if (val == ans) r = mid-1;
        else l = mid;
    }
    // cout << "s l: " << s << " " << l << ln;
    return (l == -1 ? s : e[tour[l]].y);
}

void find_pair(int32_t N, std::vector<int32_t> U, std::vector<int32_t> V, int32_t A, int32_t B) {
    n = N; m = U.size();
    FOR(i,0,m) {
        v[U[i]].PB({V[i],i});
        v[V[i]].PB({U[i],i});
        e.PB({U[i],V[i],-1LL});
    }
    dfs(0,-1);
    FOR(i,0,m) w.PB(0);
    ans = ask(w);
    // find intermediate edge
    int l = 0, r = m-1;
    while (l < r) {
        FOR(i,0,n) w[i] = 0;
        int mid = (l+r+1)/2;
        FOR(i,mid,r+1) w[tour[i]] = 1;
        int val = ask(w);
        // cout << "m a: " << mid << " " << val << ln;
        if (val == ans) r = mid-1;
        else l = mid;
    }
    int xs = e[tour[l]].x, ys = e[tour[l]].y;
    // cout << "xs ys: " << xs << " " << ys << ln;
    int32_t S = find_end(xs,ys), T = find_end(ys,xs);
    // cout << "S T: " << S << " " << T << ln;
    answer(S,T);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 2 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 2 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2512 KB Output is correct
2 Correct 13 ms 3448 KB Output is correct
3 Correct 92 ms 11804 KB Output is correct
4 Correct 103 ms 11788 KB Output is correct
5 Correct 98 ms 11788 KB Output is correct
6 Correct 121 ms 11804 KB Output is correct
7 Correct 85 ms 11804 KB Output is correct
8 Correct 76 ms 11796 KB Output is correct
9 Correct 86 ms 11860 KB Output is correct
10 Correct 78 ms 11804 KB Output is correct
11 Correct 125 ms 13620 KB Output is correct
12 Correct 117 ms 14596 KB Output is correct
13 Correct 141 ms 13784 KB Output is correct
14 Correct 121 ms 13884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 4108 KB Output is correct
2 Correct 25 ms 5916 KB Output is correct
3 Correct 24 ms 7688 KB Output is correct
4 Correct 81 ms 18388 KB Output is correct
5 Correct 91 ms 18440 KB Output is correct
6 Correct 91 ms 18440 KB Output is correct
7 Correct 77 ms 18444 KB Output is correct
8 Correct 78 ms 18396 KB Output is correct
9 Correct 67 ms 18424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2512 KB Output is correct
2 Correct 8 ms 3468 KB Output is correct
3 Correct 78 ms 10048 KB Output is correct
4 Correct 119 ms 11792 KB Output is correct
5 Correct 119 ms 11800 KB Output is correct
6 Correct 87 ms 11792 KB Output is correct
7 Correct 104 ms 11788 KB Output is correct
8 Correct 106 ms 11784 KB Output is correct
9 Correct 95 ms 11792 KB Output is correct
10 Correct 93 ms 11792 KB Output is correct
11 Correct 108 ms 13152 KB Output is correct
12 Correct 131 ms 14456 KB Output is correct
13 Correct 123 ms 13940 KB Output is correct
14 Correct 150 ms 14392 KB Output is correct
15 Correct 101 ms 11796 KB Output is correct
16 Correct 83 ms 11844 KB Output is correct
17 Correct 93 ms 14060 KB Output is correct
18 Correct 90 ms 14176 KB Output is correct
19 Correct 75 ms 11804 KB Output is correct
20 Correct 89 ms 14964 KB Output is correct
21 Correct 87 ms 11392 KB Output is correct
22 Correct 70 ms 11400 KB Output is correct
23 Correct 66 ms 11480 KB Output is correct
24 Correct 71 ms 12508 KB Output is correct
25 Correct 92 ms 18068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 173 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 157 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -