제출 #1142262

#제출 시각아이디문제언어결과실행 시간메모리
1142262dragdamRace (IOI11_race)C++17
컴파일 에러
0 ms0 KiB
#include "race.h" #include <bits/stdc++.h> #define int long long const int MAXN = 2e5+5; const int inf = 2e9; int n, r; vector<array<int,2>> g[MAXN]; int ans; map<int,int> m[MAXN]; array<int,2> o[MAXN]; void dfs(int x, int p){ for(auto k : g[x]){ if(k[0]==p) continue; dfs(k[0],x); } for(auto [k,w] : g[x]){ if(k==p) continue; o[k][0] += w; o[k][1] += 1; if(m[k].size() > m[x].size()){ swap(m[k], m[x]); swap(o[k], o[x]); } m[x][w-o[x][0]] = 1-o[x][1]; for(pair<int,int> p : m[k]){ if(m[x].find(r-p.first-o[x][0]-o[k][0])!=m[x].end()){ ans = min(ans, p.second+m[x][r-p.first-o[x][0]-o[k][0]]) + o[k][1] + o[x][1]; } p.first = p.first+o[k][0]-o[x][0]; m[x][p.first] = min(p.second+1+o[k][1], (m[x][p.first] ? m[x][p.first] : inf)); } } if(m[x].find(r-o[x][0])!=m[x].end()) ans = min(ans, m[x][r-o[x][0]] + o[x][1]); //cout << x << ' ' << o[x][0] << ' ' << o[x][1] << '\n'; //for(auto p : m[x]) cout << p.first << ' ' << p.second << '\n'; cout << '\n'; } int best_path(int N, int K, int H[][2], int L[]){ n = N; r = K; ans = inf; for(int i = 0; i < n; ++i){ g[i].clear(); m[i].clear(); o[i] = {0,0}; } for(int i = 0; i < n-1; ++i){ int x = H[i][0], y = H[i][1], w = L[i]; g[x].push_back({y,w}); g[y].push_back({x,w}); } dfs(0,0); return (ans==inf ? -1 : ans); }

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

race.cpp:9:1: error: 'vector' does not name a type
    9 | vector<array<int,2>> g[MAXN];
      | ^~~~~~
race.cpp:11:1: error: 'map' does not name a type
   11 | map<int,int> m[MAXN];
      | ^~~
race.cpp:12:1: error: 'array' does not name a type
   12 | array<int,2> o[MAXN];
      | ^~~~~
race.cpp: In function 'void dfs(long long int, long long int)':
race.cpp:15:18: error: 'g' was not declared in this scope
   15 |     for(auto k : g[x]){
      |                  ^
race.cpp:19:22: error: 'g' was not declared in this scope
   19 |     for(auto [k,w] : g[x]){
      |                      ^
race.cpp:21:9: error: 'o' was not declared in this scope
   21 |         o[k][0] += w;
      |         ^
race.cpp:23:12: error: 'm' was not declared in this scope
   23 |         if(m[k].size() > m[x].size()){
      |            ^
race.cpp:24:13: error: 'swap' was not declared in this scope
   24 |             swap(m[k], m[x]);
      |             ^~~~
race.cpp:24:13: note: suggested alternatives:
In file included from /usr/include/c++/11/regex:63,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:110,
                 from race.cpp:2:
/usr/include/c++/11/bits/regex.h:2165:5: note:   'std::__cxx11::swap'
 2165 |     swap(match_results<_Bi_iter, _Alloc>& __lhs,
      |     ^~~~
In file included from /usr/include/c++/11/bits/stl_pair.h:59,
                 from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from race.cpp:2:
/usr/include/c++/11/bits/move.h:196:5: note:   'std::swap'
  196 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
/usr/include/c++/11/bits/move.h:196:5: note:   'std::swap'
In file included from /usr/include/c++/11/exception:153,
                 from /usr/include/c++/11/ios:39,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from race.cpp:2:
/usr/include/c++/11/bits/exception_ptr.h:223:5: note:   'std::__exception_ptr::swap'
  223 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
In file included from /usr/include/c++/11/filesystem:45,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:129,
                 from race.cpp:2:
/usr/include/c++/11/bits/fs_path.h:692:15: note:   'std::filesystem::__cxx11::swap'
  692 |   inline void swap(path& __lhs, path& __rhs) noexcept { __lhs.swap(__rhs); }
      |               ^~~~
race.cpp:27:9: error: 'm' was not declared in this scope
   27 |         m[x][w-o[x][0]] = 1-o[x][1];
      |         ^
race.cpp:28:13: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
   28 |         for(pair<int,int> p : m[k]){
      |             ^~~~
      |             std::pair
In file included from /usr/include/c++/11/bits/stl_algobase.h:64,
                 from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from race.cpp:2:
/usr/include/c++/11/bits/stl_pair.h:211:12: note: 'std::pair' declared here
  211 |     struct pair
      |            ^~~~
race.cpp:3:13: error: expected primary-expression before 'long'
    3 | #define int long long
      |             ^~~~
race.cpp:28:18: note: in expansion of macro 'int'
   28 |         for(pair<int,int> p : m[k]){
      |                  ^~~
race.cpp:35:5: error: expected primary-expression before '}' token
   35 |     }
      |     ^
race.cpp:34:10: error: expected ';' before '}' token
   34 |         }
      |          ^
      |          ;
   35 |     }
      |     ~     
race.cpp:35:5: error: expected primary-expression before '}' token
   35 |     }
      |     ^
race.cpp:34:10: error: expected ')' before '}' token
   34 |         }
      |          ^
      |          )
   35 |     }
      |     ~     
race.cpp:28:12: note: to match this '('
   28 |         for(pair<int,int> p : m[k]){
      |            ^
race.cpp:35:5: error: expected primary-expression before '}' token
   35 |     }
      |     ^
race.cpp:36:8: error: 'm' was not declared in this scope
   36 |     if(m[x].find(r-o[x][0])!=m[x].end()) ans = min(ans, m[x][r-o[x][0]] + o[x][1]);
      |        ^
race.cpp:36:20: error: 'o' was not declared in this scope
   36 |     if(m[x].find(r-o[x][0])!=m[x].end()) ans = min(ans, m[x][r-o[x][0]] + o[x][1]);
      |                    ^
race.cpp:36:48: error: 'min' was not declared in this scope; did you mean 'std::min'?
   36 |     if(m[x].find(r-o[x][0])!=m[x].end()) ans = min(ans, m[x][r-o[x][0]] + o[x][1]);
      |                                                ^~~
      |                                                std::min
In file included from /usr/include/c++/11/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:65,
                 from race.cpp:2:
/usr/include/c++/11/bits/stl_algo.h:3455:5: note: 'std::min' declared here
 3455 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
race.cpp: In function 'long long int best_path(long long int, long long int, long long int (*)[2], long long int*)':
race.cpp:45:9: error: 'g' was not declared in this scope
   45 |         g[i].clear();
      |         ^
race.cpp:46:9: error: 'm' was not declared in this scope
   46 |         m[i].clear();
      |         ^
race.cpp:47:9: error: 'o' was not declared in this scope
   47 |         o[i] = {0,0};
      |         ^
race.cpp:51:9: error: 'g' was not declared in this scope
   51 |         g[x].push_back({y,w});
      |         ^