Submission #1295823

#TimeUsernameProblemLanguageResultExecution timeMemory
1295823SamueleVidThe short shank; Redemption (BOI21_prison)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) begin(x), end(x) #define rep(i,a,b) for(int i = a; i < (b); ++i) typedef long long ll; #define sz(x) (int)(x).size() typedef vector<int> vi; typedef pair<int, int> pii; void dfs(int u, vector<vi> &adj, vi &height, vi &max_depth_node) { max_depth_node[u] = u; height[u] = 0; for (auto x : adj[u]) { dfs(x, adj, height, max_depth_node); if (height[x] + 1 > height[u]) { height[u] = height[x] + 1; max_depth_node[u] = max_depth_node[x]; } } } int solve(int N, int D, int T, vector<int> t) { vi is_passive(N); ll curr_min = 1e18; for (int i = 0; i < N; i ++) { curr_min = min(curr_min + 1, t[i]); if (t[i] > T && curr_min <= T) is_passive[i] = 1; } vi p(N, -1); stack<pair<int, ll>> passive_without_parent; passive_without_parent.push({-1, -1}); // placeholder iniziale, non si toglie mai per le proprietà dei passive for (int i = 0; i < N; i ++) { // cout << "i : " << i << '\n'; // cout << "passive : " << is_passive[i] << '\n'; // if (i >= 2) return 0; if (is_passive[i]) { while (passive_without_parent.top().second < i) { // se gli ultimi non passivi dopo l'ultimo passive non fa ribellare i, che è passive // allora setto il parent dell'ultimo passive nello stack come i auto [idx, max_rebel] = passive_without_parent.top(); passive_without_parent.pop(); p[idx] = i; // sposto a sx il materasso e quindi unisco al passive precedente le influenze dei non passive a destra dell'ultimo passive passive_without_parent.top().second = max(passive_without_parent.top().second, max_rebel); } // aggiungo l'ultimo e metto materasso alla sinistra. essendo passive, t[i] > T quindi non fa ribellare nessuno (-1) passive_without_parent.push({i, -1}); } else { // aggiorno quanto in là fanno ribellare i non passive a destra dell'ultimo passive ll max_rebel = passive_without_parent.top().second; ll max_rebel_from_i = T + i - t[i]; // t[i] fa ribellare tutti i passive che si trovano entro T + i - t[i] passive_without_parent.top().second = max(max_rebel, max_rebel_from_i); } } vector<vi> adj(N); for (int i = 0; i < N; i ++) { if (!is_passive[i]) continue; if (p[i] != -1) adj[p[i]].push_back(i); } vi height(N), max_depth_node(N); vector<vi> roots_at_depth(N); for (int i = 0; i < N; i ++) { if (is_passive[i] && p[i] == -1) { dfs(i, adj, height, max_depth_node); roots_at_depth[height[i]].push_back(i); } } vi visited(N); for (int d = N - 1; d >= 0; d --) { while (D && !roots_at_depth[d].empty()) { int r = roots_at_depth[d].back(); roots_at_depth[d].pop_back(); if (visited[r]) continue; int u = max_depth_node[r]; ; while (u != -1) { for (auto x : adj[u]) { if (visited[x]) continue; p[x] = -1; roots_at_depth[height[x]].push_back(x); } visited[u] = 1; u = p[u]; } D --; } } ll sol = 0; for (int i = 0; i < N; i ++) { if (!is_passive[i] && t[i] <= T) sol ++; if (is_passive[i] && !visited[i]) sol ++; } return sol; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int N, D, T; cin >> N >> D >> T; vector<int> t(N); for (int i = 0; i < N; i ++) cin >> t[i]; cout << solve(N, D, T, t) << '\n'; }

Compilation message (stderr)

prison.cpp: In function 'int solve(int, int, int, std::vector<int>)':
prison.cpp:27:23: error: no matching function for call to 'min(ll, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   27 |         curr_min = min(curr_min + 1, t[i]);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from prison.cpp:1:
/usr/include/c++/13/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
prison.cpp:27:23: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   27 |         curr_min = min(curr_min + 1, t[i]);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:281:5: note:   template argument deduction/substitution failed:
prison.cpp:27:23: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   27 |         curr_min = min(curr_min + 1, t[i]);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5775:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5775 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5775:5: note:   template argument deduction/substitution failed:
prison.cpp:27:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   27 |         curr_min = min(curr_min + 1, t[i]);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5785:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5785 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5785:5: note:   template argument deduction/substitution failed:
prison.cpp:27:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   27 |         curr_min = min(curr_min + 1, t[i]);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~