답안 #1068443

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1068443 2024-08-21T09:54:34 Z mc061 통행료 (IOI18_highway) C++17
5 / 100
139 ms 31556 KB
#include <bits/stdc++.h>
using namespace std;

int m;
long long a, b;

long long ask(const std::vector<int> &w);
long long get(const vector<int>& busy) {
    vector<int> q(m, 0);
    for (int i : busy) q[i] = 1;
    return ask(q);
}
void answer(int s, int t);

void rec(vector<int> now, vector<vector<int>>& full, int path_le) {
    if (!now.size()) return;
    long long here = get(now);
    if (here == 1ll*path_le*a) return;
    if (here == 1ll*now.size()*b + 1ll*(path_le-now.size())*a) {
        full.push_back(now);
        return;
    }
    // random_shuffle(now.begin(), now.end());
    vector<int> left, right;
    for (int i = 0; i < now.size()/2; ++i) {
        left.push_back(now[i]);
    }
    for (int i = now.size()/2; i < now.size(); ++i) {
        right.push_back(now[i]);
    }
    rec(left, full, path_le);
    rec(right, full, path_le);
}

void find_pair(int N, std::vector<int> U, std::vector<int> V, int A_, int B_) {
    a = A_;
    b = B_;
    m = U.size();
    vector<int> v(U.size());
    iota(v.begin(), v.end(), 0);
    map<pair<int, int>, int> ind;
    vector<vector<int>> gr(N);
    for (int i = 0; i < U.size(); ++i) {
        ind[{U[i], V[i]}] = ind[{V[i], U[i]}] = i;
        gr[U[i]].push_back(V[i]);
        gr[V[i]].push_back(U[i]);
    }
    vector<int> tour;
    vector<bool> vis(N, false);
    v.clear();
    auto get_tour = [&] (auto&& self, int X) -> void {
        tour.push_back(X);
        vis[X] = true;
        for (int u : gr[X]) if (!vis[u]) {
            v.push_back(ind[{X, u}]);
            self(self, u);
        }
    };
    get_tour(get_tour, 0);
    vector<vector<int>> full;
    long long path_le = get(v) / b;
    rec(v, full, path_le);
    map<int, int> c;
    for (auto& x : full) {
        for (int j : x) {
            c[U[j]]++;
            c[V[j]]++;
        }
    }
    vector<int> vs;
    for (auto [x, y] : c) {
        if (y == 1) vs.push_back(x);
    }
    answer(vs[0], vs[1]);
}

Compilation message

highway.cpp: In function 'void rec(std::vector<int>, std::vector<std::vector<int> >&, int)':
highway.cpp:19:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
   19 |     if (here == 1ll*now.size()*b + 1ll*(path_le-now.size())*a) {
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
highway.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int i = 0; i < now.size()/2; ++i) {
      |                     ~~^~~~~~~~~~~~~~
highway.cpp:28:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (int i = now.size()/2; i < now.size(); ++i) {
      |                                ~~^~~~~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int i = 0; i < U.size(); ++i) {
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 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 1 ms 344 KB Output is correct
9 Correct 1 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 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 3768 KB Output is correct
2 Correct 27 ms 6992 KB Output is correct
3 Correct 40 ms 10424 KB Output is correct
4 Correct 137 ms 30612 KB Output is correct
5 Correct 117 ms 30504 KB Output is correct
6 Incorrect 139 ms 31556 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 600 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 24 ms 3084 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 18 ms 3072 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -