Submission #1049990

# Submission time Handle Problem Language Result Execution time Memory
1049990 2024-08-09T06:40:03 Z otarius Race (IOI11_race) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()

// #define int long long
// #define int unsigned long long

#define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>

void open_file(string filename) {
    freopen((filename + ".in").c_str(), "r", stdin);
    freopen((filename + ".out").c_str(), "w", stdout);
}

// const ll mod = 1e9 + 7;
// const ll mod = 998244353;

const ll inf = 1e9;
const ll biginf = 1e18;
const int maxN = 5 * 1e5 + 5;

vector<int> g[maxN];
map<int, int> dp[maxN];
int n, k, dep[maxN], sum[maxN], ans = inf;
void dfs(int v, int par, int len, int val) {
    dp[v][sum[v]] = dep[v];
    dep[v] = len; sum[v] = val;
    for (pii u : g[v]) {
        if (u.ff == par) continue;
        dfs(u.ff, v, len + 1, val + u.sc);
        for (pii u : g[v]) {
            if (u.ff == par) continue;
            if (dp[u.ff].size() > dp[v].size())
                swap(dp[u.ff], dp[v]);
            for (auto x : dp[u.ff]) {
                if (dp[v].find(k + 2 * sum[v] - x.ff) != dp[v].end()) {
                    ans = min(ans, dp[v][k + 2 * sum[v] - x.ff] + x.sc - 2 * dep[v]);
                }
            } for (auto x : dp[u.ff]) {
                if (dp[v].find(x.ff) == dp[v].end())
                    dp[v][x.ff] = x.sc;
                else dp[v][x.ff] = min(dp[v][x.ff], x.sc);
            }
        }
    }
}
int best_path(int _n, int _k, int h[][2], int l[]) {
    n = _n; k = _k;
    for (int i = 0; i < n - 1; i++) {
        g[h[i][0]].pb({h[i][1], l[i]});
        g[h[i][1]].pb({h[i][0], l[i]});
    } dfs(0, -1, 0, 0);
    return ans;
}

Compilation message

race.cpp: In function 'void dfs(int, int, int, int)':
race.cpp:43:21: error: conversion from 'int' to non-scalar type 'std::pair<int, int>' requested
   43 |     for (pii u : g[v]) {
      |                     ^
race.cpp:46:25: error: conversion from 'int' to non-scalar type 'std::pair<int, int>' requested
   46 |         for (pii u : g[v]) {
      |                         ^
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:65:38: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   65 |         g[h[i][0]].pb({h[i][1], l[i]});
      |                                      ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from race.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const int&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
race.cpp:66:38: error: no matching function for call to 'std::vector<int>::push_back(<brace-enclosed initializer list>)'
   66 |         g[h[i][1]].pb({h[i][0], l[i]});
      |                                      ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from race.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const int&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
race.cpp: In function 'void open_file(std::string)':
race.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     freopen((filename + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
race.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen((filename + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~