답안 #1077901

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077901 2024-08-27T10:17:54 Z vladilius 통행료 (IOI18_highway) C++17
5 / 100
91 ms 36544 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
#define ins insert

void find_pair(int n, vector<int> U, vector<int> V, int A, int B){
    if (U.size() != (n - 1)){
        answer(0, 0);
        return;
    }
    vector<pii> g[n + 1];
    for (int i = 0; i < n - 1; i++){
        U[i]++; V[i]++;
        g[U[i]].pb({V[i], i});
        g[V[i]].pb({U[i], i});
    }
    
    vector<int> w(n - 1);
    ll nl = ask(w);
    
    auto em = [&](){
        fill(w.begin(), w.end(), 0);
    };
    
    vector<int> all;
    for (int i = 0; i < n - 1; i++) all.pb(i);
    
    while (all.size() > 1){
        int m = (int) (all.size()) / 2;
        em();
        for (int i = 0; i < m; i++){
            w[all[i]] = 1;
        }
        
        ll g = ask(w);
        if (g == nl){
            reverse(all.begin(), all.end());
            m = (int) all.size() - m;
            while (all.size() > m) all.pop_back();
        }
        else {
            while (all.size() > m) all.pop_back();
        }
    }
    
    int T = all[0], x = U[T], y = V[T];
    
    vector<int> d(n + 1), p(n + 1), pe(n + 1);
    function<void(int, int, int, vector<pii>&, vector<int>&)> dfs = [&](int v, int pr, int ed, vector<pii>& k, vector<int>& t){
        t.pb(v);
        p[v] = pr; pe[v] = ed;
        if (ed != -1) k.pb({pr, ed});
        for (auto [i, j]: g[v]){
            if (i == pr || j == T) continue;
            d[i] = d[v] + 1;
            dfs(i, v, j, k, t);
        }
    };
    
    vector<pii> c1, c2;
    vector<int> q1, q2;
    d[x] = d[y] = 0;
    dfs(x, 0, -1, c1, q1);
    dfs(y, 0, -1, c2, q2);
    
    auto add = [&](int v){
        while (pe[v] != -1){
            w[pe[v]] = 1;
            v = p[v];
        }
    };
    
    nl /= A;
    
    auto solve = [&](vector<pii> t1, vector<pii> t2, vector<int> q){
        em();
        for (auto [i, j]: t2) w[j] = 1;
        int dd = (int) (ask(w) - B * (nl - 1) - A) / (A - B);

        vector<int> all;
        for (int i: q){
            if (d[i] == dd){
                all.pb(i);
            }
        }

        while (all.size() > 1){
            int m = (int) (all.size()) / 2;
            em();
            for (int i = 0; i < m; i++){
                add(all[i]);
            }
            
            ll S = ask(w);
            if (S == (1LL * B * dd + 1LL * A * (nl - dd))){
                while (all.size() > m) all.pop_back();
            }
            else {
                reverse(all.begin(), all.end());
                m = (int) all.size() - m;
                while (all.size() > m) all.pop_back();
            }
        }
        
        return (all[0] - 1);
    };
    
    answer(solve(c1, c2, q1), solve(c2, c1, q2));
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:12:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   12 |     if (U.size() != (n - 1)){
      |         ~~~~~~~~~^~~~~~~~~~
highway.cpp:44:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   44 |             while (all.size() > m) all.pop_back();
      |                    ~~~~~~~~~~~^~~
highway.cpp:47:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |             while (all.size() > m) all.pop_back();
      |                    ~~~~~~~~~~~^~~
highway.cpp: In lambda function:
highway.cpp:101:35: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  101 |                 while (all.size() > m) all.pop_back();
      |                        ~~~~~~~~~~~^~~
highway.cpp:106:35: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  106 |                 while (all.size() > m) all.pop_back();
      |                        ~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 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 0 ms 344 KB Output is correct
10 Correct 0 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 344 KB Output is correct
2 Correct 10 ms 1608 KB Output is correct
3 Correct 84 ms 12180 KB Output is correct
4 Correct 79 ms 11956 KB Output is correct
5 Correct 91 ms 12032 KB Output is correct
6 Correct 73 ms 11956 KB Output is correct
7 Correct 75 ms 11860 KB Output is correct
8 Correct 74 ms 11944 KB Output is correct
9 Correct 77 ms 12208 KB Output is correct
10 Correct 75 ms 11948 KB Output is correct
11 Correct 75 ms 13216 KB Output is correct
12 Correct 87 ms 15200 KB Output is correct
13 Correct 78 ms 13644 KB Output is correct
14 Runtime error 81 ms 26532 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2392 KB Output is correct
2 Correct 15 ms 4420 KB Output is correct
3 Correct 23 ms 6856 KB Output is correct
4 Correct 69 ms 16340 KB Output is correct
5 Correct 66 ms 17588 KB Output is correct
6 Correct 68 ms 18608 KB Output is correct
7 Correct 67 ms 21152 KB Output is correct
8 Correct 63 ms 16324 KB Output is correct
9 Runtime error 79 ms 36544 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 8 ms 1532 KB Output is correct
3 Correct 67 ms 9656 KB Output is correct
4 Correct 73 ms 11940 KB Output is correct
5 Correct 72 ms 11948 KB Output is correct
6 Correct 74 ms 12004 KB Output is correct
7 Correct 72 ms 11944 KB Output is correct
8 Correct 71 ms 11948 KB Output is correct
9 Correct 80 ms 12240 KB Output is correct
10 Correct 82 ms 12200 KB Output is correct
11 Runtime error 82 ms 25524 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 600 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 600 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -