제출 #1161459

#제출 시각아이디문제언어결과실행 시간메모리
1161459JahonaliX경주 (Race) (IOI11_race)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;

int best_path(int n, int k, int h[][2], int l[]) {
    int z = n;
    vector<vector<pair<int, int>>> a(n);
    for (int i = 0; i + 1 < n; ++i) a[h[i][0]].emplace_back(h[i][1], l[i]), a[h[i][1]].emplace_back(h[i][0], l[i]);
    function<vector<int>(int)> dfs = [&] (int i, int p, int w) {
        vector<int> dp(k + 1, -1);
        dp[0] = 0;
        for (auto [j, wtf] : a[i]) {
            if (p[i] != j) {
                auto x = dfs(j, i, wtf);
                for (int y = 0; y <= k; ++y) if (~dp[k - y] && ~x[y]) z = min(z, dp[k - y] + x[y]);
                for (int y = 0; y <= k; ++y) {
                    if (~x[y]) {
                        if (~dp[y]) dp[y] = min(dp[y], x[y]);
                        else dp[y] = x[y];
                    }
                }
            }
        }
        for (int y = k - wtf; y >= 0; --y) dp[y + wtf] = dp[y]; 
        if (~dp[k]) z = min(z, dp[k]);
        return dp;
    };
    dfs(0, 0, 0);
    return z;
}

컴파일 시 표준 에러 (stderr) 메시지

race.cpp: In lambda function:
race.cpp:13:18: error: invalid types 'int[int]' for array subscript
   13 |             if (p[i] != j) {
      |                  ^
race.cpp:14:29: error: no match for call to '(std::function<std::vector<int>(int)>) (std::tuple_element<0, std::pair<int, int> >::type&, int&, std::tuple_element<1, std::pair<int, int> >::type&)'
   14 |                 auto x = dfs(j, i, wtf);
      |                          ~~~^~~~~~~~~~~
In file included from /usr/include/c++/11/functional:59,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from race.cpp:1:
/usr/include/c++/11/bits/std_function.h:586:7: note: candidate: '_Res std::function<_Res(_ArgTypes ...)>::operator()(_ArgTypes ...) const [with _Res = std::vector<int>; _ArgTypes = {int}]'
  586 |       operator()(_ArgTypes... __args) const
      |       ^~~~~~~~
/usr/include/c++/11/bits/std_function.h:586:7: note:   candidate expects 1 argument, 3 provided
race.cpp:24:26: error: 'wtf' was not declared in this scope
   24 |         for (int y = k - wtf; y >= 0; --y) dp[y + wtf] = dp[y];
      |                          ^~~
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:27:5: error: conversion from 'best_path(int, int, int (*)[2], int*)::<lambda(int, int, int)>' to non-scalar type 'std::function<std::vector<int>(int)>' requested
   27 |     };
      |     ^
race.cpp:28:8: error: no match for call to '(std::function<std::vector<int>(int)>) (int, int, int)'
   28 |     dfs(0, 0, 0);
      |     ~~~^~~~~~~~~
In file included from /usr/include/c++/11/functional:59,
                 from /usr/include/c++/11/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/11/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from race.cpp:1:
/usr/include/c++/11/bits/std_function.h:586:7: note: candidate: '_Res std::function<_Res(_ArgTypes ...)>::operator()(_ArgTypes ...) const [with _Res = std::vector<int>; _ArgTypes = {int}]'
  586 |       operator()(_ArgTypes... __args) const
      |       ^~~~~~~~
/usr/include/c++/11/bits/std_function.h:586:7: note:   candidate expects 1 argument, 3 provided