답안 #1081911

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1081911 2024-08-30T12:50:12 Z vladilius 통행료 (IOI18_highway) C++17
51 / 100
160 ms 24016 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second

void find_pair(int n, vector<int> U, vector<int> V, int A, int B){
    int m = (int) U.size();
    vector<pii> g[n + 1];
    for (int i = 0; i < m; i++){
        U[i]++; V[i]++;
        g[U[i]].pb({V[i], i});
        g[V[i]].pb({U[i], i});
    }
    
    vector<int> w(m);
 
    ll nl = ask(w);
    int l = 0, r = m - 1;
    while (l + 1 < r){
        int k = (l + r) / 2;
        fill(w.begin(), w.end(), 0);
        for (int i = k + 1; i < m; i++) w[i] = 1;
        if (ask(w) == nl){
            r = k;
        }
        else {
            l = k + 1;
        }
    }
    
    fill(w.begin(), w.end(), 0);
    for (int i = l + 1; i < m; i++) w[i] = 1;
    if (ask(w) == nl){
        r = l;
    }
    int x = r;
 
    vector<bool> used(n + 1);
    vector<int> ed = {x};
    queue<int> q;
    q.push(V[x]);
    q.push(U[x]);
    used[V[x]] = used[U[x]] = 1;
    while (!q.empty()){
        int f = q.front(); q.pop();
        for (auto [i, j]: g[f]){
            if (used[i] || j == x) continue;
            used[i] = 1;
            q.push(i);
            ed.pb(j);
        }
    }
    
    fill(w.begin(), w.end(), 1);
    
    auto cl = [&](){
        for (int i: ed) w[i] = 0;
    };
    
    cl();
    vector<pii> t[n + 1];
    for (int i: ed){
        t[U[i]].pb({V[i], i});
        t[V[i]].pb({U[i], i});
    }
    
    vector<int> d(n + 1), p(n + 1), pe(n + 1);
    function<void(int, int, vector<int>&, vector<int>&)> dfs = [&](int v, int pr, vector<int>& ed, vector<int>& q){
        q.pb(v);
        p[v] = pr;
        for (auto [i, j]: t[v]){
            if (i == pr || j == x) continue;
            d[i] = d[v] + 1;
            pe[i] = j;
            ed.pb(j);
            dfs(i, v, ed, q);
        }
    };
    
    vector<int> d1, d2, t1, t2;
    dfs(U[x], 0, d1, t1);
    dfs(V[x], 0, d2, t2);
    
    int dist = (int) (ask(w) / A);

    auto cmp = [&](int x, int y){
        return (d[x] < d[y]);
    };
    
    auto solve = [&](int v, vector<int>& x1, vector<int>& x2, vector<int> vv){
        cl();
        for (int i: x2) w[i] = 1;
        sort(vv.begin(), vv.end(), cmp);
        
        int ds = (int) ((ask(w) + B - A - 1LL * dist * B) / (A - B));
        
        auto check = [&](int k){
            cl();
            for (int i = 0; i <= k; i++){
                if (vv[i] != v) w[pe[vv[i]]] = 1;
            }
            return (ask(w) == (1LL * B * ds + 1LL * A * (dist - ds)));
        };
        
        int l = 0, r = (int) vv.size() - 1;
        while (l + 1 < r){
            int k = (l + r) / 2;
            if (check(k)){
                r = k;
            }
            else {
                l = k + 1;
            }
        }
        
        if (check(l)) r = l;
        
        return (vv[r] - 1);
    };
    
    answer(solve(U[x], d1, d2, t1), solve(V[x], d2, d1, t2));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 452 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 10 ms 2132 KB Output is correct
3 Correct 106 ms 15808 KB Output is correct
4 Correct 110 ms 15816 KB Output is correct
5 Correct 106 ms 15800 KB Output is correct
6 Correct 104 ms 15856 KB Output is correct
7 Correct 94 ms 15808 KB Output is correct
8 Correct 98 ms 15684 KB Output is correct
9 Correct 99 ms 16088 KB Output is correct
10 Correct 103 ms 15804 KB Output is correct
11 Correct 107 ms 16932 KB Output is correct
12 Correct 123 ms 18200 KB Output is correct
13 Correct 109 ms 17156 KB Output is correct
14 Correct 112 ms 17552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 2904 KB Output is correct
2 Correct 17 ms 5016 KB Output is correct
3 Correct 27 ms 8016 KB Output is correct
4 Correct 97 ms 20344 KB Output is correct
5 Correct 81 ms 20852 KB Output is correct
6 Correct 84 ms 23192 KB Output is correct
7 Correct 81 ms 24016 KB Output is correct
8 Correct 89 ms 21352 KB Output is correct
9 Correct 87 ms 22412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 11 ms 2136 KB Output is correct
3 Correct 71 ms 12588 KB Output is correct
4 Correct 102 ms 15816 KB Output is correct
5 Correct 93 ms 15800 KB Output is correct
6 Correct 88 ms 15792 KB Output is correct
7 Correct 99 ms 15796 KB Output is correct
8 Correct 92 ms 15784 KB Output is correct
9 Correct 112 ms 15756 KB Output is correct
10 Correct 103 ms 16004 KB Output is correct
11 Correct 104 ms 16576 KB Output is correct
12 Correct 130 ms 18132 KB Output is correct
13 Correct 138 ms 17168 KB Output is correct
14 Correct 121 ms 17648 KB Output is correct
15 Correct 90 ms 15668 KB Output is correct
16 Correct 94 ms 15668 KB Output is correct
17 Correct 112 ms 17172 KB Output is correct
18 Correct 119 ms 17292 KB Output is correct
19 Correct 99 ms 15812 KB Output is correct
20 Correct 101 ms 18276 KB Output is correct
21 Correct 87 ms 16464 KB Output is correct
22 Correct 85 ms 16716 KB Output is correct
23 Correct 95 ms 16204 KB Output is correct
24 Correct 97 ms 16700 KB Output is correct
25 Correct 160 ms 23716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 2136 KB Output is correct
2 Correct 11 ms 2136 KB Output is correct
3 Incorrect 144 ms 16348 KB Output is incorrect: {s, t} is wrong.
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 2136 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -