제출 #1231407

#제출 시각아이디문제언어결과실행 시간메모리
1231407rhm_ganDreaming (IOI13_dreaming)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #include "dreaming.h" using namespace std; const short N = 1e5; struct Graph { vector<vector<pair<short, short>>> g; vector<short> dp1, dp2, res; short x, cnt; Graph() { g.resize(N); dp1.resize(N); dp2.resize(N); res.resize(N); x = cnt = 0; } void add(short a, short b, short w) { x = a; g[a].push_back({b, w}); g[b].push_back({a, w}); cnt++; } void dfs1(short u, short p) { for (auto [v, w] : g[u]) { if (v == p) continue; dfs1(v, u); if (dp1[v] + w >= dp1[u]) { dp2[u] = dp1[u]; dp1[u] = dp1[v] + w; } else { dp2[u] = max(dp2[u], dp1[v] + w); } } res[u] = max(res[u], dp1[u]); } void dfs2(short u, short p, short d) { res[u] = max(res[u], d); for (auto [v, w] : g[u]) { if (v == p) continue; short k = 0; if (dp1[v] + w == dp1[u]) { k = dp2[u]; } else { k = dp1[u]; } dfs2(v, u, max(k, d) + w); } } short findmin() { dfs1(x, -1); dfs2(x, -1, 0); short mn = 1e9; for (short i = 0; i < N; i++) { if (res[i] != 0) { mn = min(mn, res[i]); } } for (short i = 0; i < N; i++) { if (res[i] == mn) { return i; } } return -1; } bool empty() { return cnt == 0; } void clear() { g.assign(N, vector<pair<short, short>>()); dp1.assign(N, 0); dp2.assign(N, 0); res.assign(N, 0); x = cnt = 0; } }; vector<pair<short, short>> adj[N]; vector<Graph> g; Graph tmp; bool vis[N]; void dfs(short u) { vis[u] = 1; for (auto [v, w] : adj[u]) { if (!vis[v]) { tmp.add(u, v, w); dfs(v); } } } short travelTime(short n, short m, short l, short a[], short b[], short t[]) { Graph res; vector<bool> is(n); for (short i = 0; i < m; i++) { short u = a[i], v = b[i], w = t[i]; is[u] = is[v] = 1; adj[u].push_back({v, w}); adj[v].push_back({u, w}); res.add(u, v, w); } for (short i = 0; i < n; i++) { if (!vis[i]) { tmp.clear(); dfs(i); g.push_back(tmp); } } vector<short> v; for (short i = 0; i < n; i++) { if (!is[i]) { v.push_back(i); } } for (short i = 0; i < g.size(); i++) { if (!g[i].empty()) { v.push_back(g[i].findmin()); } } for (short i = 1; i < v.size(); i++) { res.add(v[i], v[i - 1], l); } short id = res.findmin(); short ans = 0; for (short i = 0; i < N; i++) { ans = max(ans, res.res[i]); } return ans; }

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

dreaming.cpp:5:17: warning: overflow in conversion from 'double' to 'short int' changes value from '1.0e+5' to '32767' [-Woverflow]
    5 | const short N = 1e5;
      |                 ^~~
dreaming.cpp: In member function 'void Graph::dfs1(short int, short int)':
dreaming.cpp:36:29: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<short int>, short int>::value_type&, int)'
   36 |                 dp2[u] = max(dp2[u], dp1[v] + w);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~
In file included 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 dreaming.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
dreaming.cpp:36:29: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
   36 |                 dp2[u] = max(dp2[u], dp1[v] + w);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~
In file included 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 dreaming.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
dreaming.cpp:36:29: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
   36 |                 dp2[u] = max(dp2[u], dp1[v] + w);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 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 dreaming.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3461:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3461 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3461:5: note:   template argument deduction/substitution failed:
dreaming.cpp:36:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
   36 |                 dp2[u] = max(dp2[u], dp1[v] + w);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 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 dreaming.cpp:1:
/usr/include/c++/11/bits/stl_algo.h:3467:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3467 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3467:5: note:   template argument deduction/substitution failed:
dreaming.cpp:36:29: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
   36 |                 dp2[u] = max(dp2[u], dp1[v] + w);
      |                          ~~~^~~~~~~~~~~~~~~~~~~~
dreaming.cpp: In member function 'short int Graph::findmin()':
dreaming.cpp:60:20: warning: overflow in conversion from 'double' to 'short int' changes value from '1.0e+9' to '32767' [-Woverflow]
   60 |         short mn = 1e9;
      |                    ^~~
dreaming.cpp: At global scope:
dreaming.cpp:87:32: error: size of array 'adj' exceeds maximum object size '9223372036854775807'
   87 | vector<pair<short, short>> adj[N];
      |                                ^
dreaming.cpp:91:10: error: size of array 'vis' exceeds maximum object size '9223372036854775807'
   91 | bool vis[N];
      |          ^