답안 #964293

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964293 2024-04-16T15:02:51 Z steveonalex 통행료 (IOI18_highway) C++17
51 / 100
238 ms 262144 KB
#include <bits/stdc++.h>
#include "highway.h"
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define ALL(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
 
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng(1);
ll rngesus(ll l, ll r){return ((ull) rng()) % (r - l + 1) + l;}
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
 
ll LASTBIT(ll mask){return mask & (-mask);}
ll pop_cnt(ll mask){return __builtin_popcountll(mask);}
ll ctz(ll mask){return __builtin_ctzll(mask);}
ll clz(ll mask){return __builtin_clzll(mask);}
ll logOf(ll mask){return 63 - clz(mask);}
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b){a = b; return true;}
        return false;
    }
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b){a = b; return true;}
        return false;
    }
template <class T>
    void printArr(T& a, string separator = " ", string finish = "\n", ostream& out = cout){
        for(auto i: a) out << i << separator;
        out << finish;
    }
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

const int N = 1e5 + 69;
int n, m;
vector<pair<int, int>> graph[N];
int h[N];

void dfs(int u, int p, vector<int> &topo){
    for(pair<int, int> v: graph[u]) if (v.first != p){
        h[v.first] = h[u] + 1;
        dfs(v.first, u, topo);
        topo.push_back(v.second);
    }
}

struct P{
    ll i, w;
    P(){}
    P(ll _i, ll _w){i = _i, w = _w;}
};

struct compare{
    bool operator () (P a, P b) {return a.w > b.w;}
};

// namespace Grader{
//     int n;
//     int s, t;
//     int x, y;
//     vector<int> U, V;
//     int A, B;
//     int o_cnt = 0;

//     ll ask(vector<int> w){
//         o_cnt++;
//         vector<P> graph[n];
//         for(int i = 0; i<w.size(); ++i){
//             int u = U[i], v = V[i];
//             int cur_w = A;
//             if (w[i]) cur_w = B;
//             graph[u].push_back(P(v, cur_w));
//             graph[v].push_back(P(u, cur_w));
//         }
//         vector<ll> dis(n+1, 1e18);
//         dis[s] = 0;
//         priority_queue<P, vector<P>, compare> pq; 
//         pq.push(P(s, 0));
//         while(pq.size()){
//             P u= pq.top(); pq.pop();
//             for(P v: graph[u.i]) if (minimize(dis[v.i], dis[u.i] + v.w)) 
//                 pq.push(P(v.i, dis[v.i]));
//         }
//         return dis[t];
//     }

//     void answer(int _x, int _y){
//         x = _x, y = _y;
//     }

    void find_pair(int _n, vector<int> U, vector<int> V, int A, int B) {
        n = _n, m = U.size();
        for(int i = 0; i<n; ++i) graph[i].clear();
        for(int i = 0; i<m; ++i){
            int u = U[i], v = V[i];
            graph[u].push_back({v, i});
            graph[v].push_back({u, i});
        }

        ll initial = ask(vector<int>(m));

        vector<int> topo;
        dfs(0, 0, topo);

        int l= 0, r = topo.size();
        while(l < r){
            int mid = (l + r) >> 1;
            vector<int> w(m);
            for(int i = 0; i<=mid; ++i) w[topo[i]] = 1;
            if (ask(w) > initial) r = mid;
            else l = mid + 1;
        }

        int x;
        if (l == topo.size()) x = 0;
        else{
            int e = topo[l];
            if (h[U[e]] > h[V[e]]) x = U[e];
            else x = V[e];
        }

        topo.clear();
        h[x] = 0;
        dfs(x, x, topo);

        l= 0, r = topo.size() - 1;
        while(l < r){
            int mid = (l + r) >> 1;
            vector<int> w(m);
            for(int i = 0; i<=mid; ++i) w[topo[i]] = 1;
            if (ask(w) > initial) r = mid;
            else l = mid + 1;
        }
        int e = topo[l];
        int y;
        if (h[U[e]] == initial / A) y = U[e];
        else y = V[e];

        answer(x, y);

    }

//     pair<bool, int> solve(int _n){
//         n = _n;
//         U.clear(); V.clear();
//         x = y = -1;
//         o_cnt = 0;
//         for(int i= 1; i<n; ++i){
//             U.push_back(rngesus(0, i-1));
//             V.push_back(i);
//             if (rngesus(0, 1)) swap(U.back(), V.back());
//         }

//         s = rngesus(0, n-1);
//         t = s;
//         while(t == s) t = rngesus(0, n-1);

//         A = 1, B = 2;

//         find_pair(n, U, V, A, B);

//         if (x > y) swap(x, y);
//         if (s > t) swap(s, t);
//         return make_pair(make_pair(x, y) == make_pair(s, t), o_cnt);
//     }
// }


// int main(void){
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//     for(int iteration = 1; iteration <= 100; ++iteration){
//         pair<bool, int> verdict = Grader::solve(5);
//         if (verdict.first) cout << "AC\n";
//         else cout << "WA\n";

//         cout << "Operation count: " << verdict.second << "\n";
//     }

//     return 0;
// }

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:128:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  128 |         if (l == topo.size()) x = 0;
      |             ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3160 KB Output is correct
2 Correct 1 ms 3016 KB Output is correct
3 Correct 2 ms 3268 KB Output is correct
4 Correct 1 ms 3016 KB Output is correct
5 Correct 2 ms 3008 KB Output is correct
6 Correct 1 ms 3016 KB Output is correct
7 Correct 1 ms 3012 KB Output is correct
8 Correct 1 ms 3012 KB Output is correct
9 Correct 1 ms 3012 KB Output is correct
10 Correct 1 ms 3016 KB Output is correct
11 Correct 1 ms 3012 KB Output is correct
12 Correct 1 ms 3020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3068 KB Output is correct
2 Correct 13 ms 3736 KB Output is correct
3 Correct 90 ms 9292 KB Output is correct
4 Correct 96 ms 9524 KB Output is correct
5 Correct 86 ms 9056 KB Output is correct
6 Correct 102 ms 9048 KB Output is correct
7 Correct 97 ms 9296 KB Output is correct
8 Correct 98 ms 9044 KB Output is correct
9 Correct 109 ms 9068 KB Output is correct
10 Correct 84 ms 9048 KB Output is correct
11 Correct 95 ms 10556 KB Output is correct
12 Correct 115 ms 11508 KB Output is correct
13 Correct 112 ms 10760 KB Output is correct
14 Correct 128 ms 10908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 4612 KB Output is correct
2 Correct 26 ms 6200 KB Output is correct
3 Correct 24 ms 7740 KB Output is correct
4 Correct 71 ms 16952 KB Output is correct
5 Correct 94 ms 16968 KB Output is correct
6 Correct 67 ms 16964 KB Output is correct
7 Correct 94 ms 16948 KB Output is correct
8 Correct 71 ms 17684 KB Output is correct
9 Correct 107 ms 16708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3068 KB Output is correct
2 Correct 11 ms 3728 KB Output is correct
3 Correct 74 ms 7492 KB Output is correct
4 Correct 92 ms 9068 KB Output is correct
5 Correct 89 ms 9276 KB Output is correct
6 Correct 87 ms 9076 KB Output is correct
7 Correct 114 ms 9304 KB Output is correct
8 Correct 136 ms 9048 KB Output is correct
9 Correct 108 ms 9248 KB Output is correct
10 Correct 119 ms 9060 KB Output is correct
11 Correct 110 ms 10340 KB Output is correct
12 Correct 92 ms 11720 KB Output is correct
13 Correct 97 ms 11128 KB Output is correct
14 Correct 98 ms 11724 KB Output is correct
15 Correct 83 ms 9296 KB Output is correct
16 Correct 79 ms 9568 KB Output is correct
17 Correct 114 ms 11084 KB Output is correct
18 Correct 99 ms 11728 KB Output is correct
19 Correct 89 ms 9052 KB Output is correct
20 Correct 91 ms 12200 KB Output is correct
21 Correct 91 ms 9664 KB Output is correct
22 Correct 96 ms 9432 KB Output is correct
23 Correct 86 ms 9340 KB Output is correct
24 Correct 76 ms 10092 KB Output is correct
25 Correct 121 ms 16104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 238 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 187 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -