Submission #1070827

# Submission time Handle Problem Language Result Execution time Memory
1070827 2024-08-22T19:13:09 Z MohamedFaresNebili Closing Time (IOI23_closing) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "closing.h"

        using namespace std;

        vector<pair<int, long long>> adj[200005];
        long long D[200005][2];
        vector<long long> pL, pR, pM;
        void dfs(int X, int p, int st) {
            for(auto u : adj[X]) {
                if(u.first == p) continue;
                D[u.first][st] = D[X][st] + u.second;
                dfs(u.first, X, st);
            }
        }
        long long sum(int l, int r, vector<long long> arr) {
            return arr[r] - (l > 0 ? arr[l - 1] : 0);
        }

        int max_score(int N, int X, int Y, long long K,
            vector<int> U, vector<int> V, vector<int> W) {
            pL.resize(N); pR.resize(N); pM.resize(N);
            for(int l = 0; l < N; l++) D[l][0] = D[l][1] = 2e18 + 7, adj[l].clear();
            for(int l = 0; l < N - 1; l++) {
                adj[U[l]].push_back({V[l], W[l]});
                adj[V[l]].push_back({U[l], W[l]});
            }
            if(X > Y) swap(X, Y);
            D[X][0] = 0, D[Y][1] = 0;
            dfs(X, X, 0); dfs(Y, Y, 1);
            for(int l = 0; l < N; l++) {
                pL[l] = D[l][0];
                pR[l] = D[l][1];
                pM[l] = min(D[l][0], D[l][1]);
                if(l > 0) {
                    pL[l] += pL[l - 1];
                    pR[l] += pR[l - 1];
                    pM[l] += pM[l - 1];
                }
            }
            int res = 0;
            for(int l = 0; l < N; l++) {
                for(int i = l; i < N; i++) {
                    int lo = l, hi = i;
                    long long calc = sum(l, i, pL) + sum(l, i, pR) - sum(l, i, pM);
                    if(calc > K) continue;
                    int cur = i - l + 1;
                    priority_queue<pair<int, long long>, vector<pair<int, long long>>, greater<pair<int, long long>>> pq;
                    if(i < N - 1) pq.push({min(D[i + 1][0], D[i + 1][1]0, i + 1});
                    if(l > 0) pq.push({min(D[l - 1][0], D[l - 1][1]), l - 1});
                    while(!pq.empty()) {
                        int x = pq.top().second; long long w = pq.top().first;
                        pq.pop(); calc += w;
                        if(calc > K) break;
                        ++cur; lo = min(lo, x), hi = max(hi, x);
                        if(x > i && x < N - 1) pq.push({min(D[x + 1][0], D[x + 1][1]), x + 1});
                        if(x < l && x > 0) pq.push({min(D[x - 1][0], D[x - 1][1]), x - 1});
                    }
                    if(X >= lo && Y <= hi) res = max(res, cur);
                }
            }

            vector<int> belong(N, -1);
            belong[X] = 0, belong[Y] = 1;
            priority_queue<array<long long, 3>, vector<array<long long, 3>>, greater<array<long long, 3>>> pq;
            pq.push({0, X, 0}); pq.push({0, Y, 1});
            int cur = 0; long long calc = 0;
            while(!pq.empty()) {
                int a = pq.top()[1], st = pq.top()[2];
                long long w = pq.top()[0]; pq.pop();
                if(calc + w > K) break;
                if(belong[a] != -1) continue;
                belong[a] = st; calc += w; cur++;
                if(a > 0) {
                    int b = a - 1;
                    if(belong[b] == -1) {
                        array<long long, 3> arr = {D[b][st], b, st};
                        pq.push(arr);
                    }
                }
                if(a < N - 1) {
                    int b = a + 1;
                    if(belong[b] == -1) {
                        array<long long, 3> arr = {D[b][st], b, st};
                        pq.push(arr);
                    }
                }
            }
            res = max(res, cur);
            return res;
        }

Compilation message

closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:49:72: error: expected ')' before numeric constant
   49 |                     if(i < N - 1) pq.push({min(D[i + 1][0], D[i + 1][1]0, i + 1});
      |                                               ~                        ^
      |                                                                        )
closing.cpp:49:80: error: expected ')' before '}' token
   49 |                     if(i < N - 1) pq.push({min(D[i + 1][0], D[i + 1][1]0, i + 1});
      |                                               ~                                ^
      |                                                                                )
closing.cpp:49:81: error: no matching function for call to 'std::priority_queue<std::pair<int, long long int>, std::vector<std::pair<int, long long int> >, std::greater<std::pair<int, long long int> > >::push(<brace-enclosed initializer list>)'
   49 |                     if(i < N - 1) pq.push({min(D[i + 1][0], D[i + 1][1]0, i + 1});
      |                                                                                 ^
In file included from /usr/include/c++/10/queue:64,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from closing.cpp:1:
/usr/include/c++/10/bits/stl_queue.h:640:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = std::pair<int, long long int>; _Sequence = std::vector<std::pair<int, long long int> >; _Compare = std::greater<std::pair<int, long long int> >; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = std::pair<int, long long int>]'
  640 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_queue.h:640:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<int, long long int>&'}
  640 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_queue.h:648:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(std::priority_queue<_Tp, _Sequence, _Compare>::value_type&&) [with _Tp = std::pair<int, long long int>; _Sequence = std::vector<std::pair<int, long long int> >; _Compare = std::greater<std::pair<int, long long int> >; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = std::pair<int, long long int>]'
  648 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_queue.h:648:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<std::pair<int, long long int>, std::vector<std::pair<int, long long int> >, std::greater<std::pair<int, long long int> > >::value_type&&' {aka 'std::pair<int, long long int>&&'}
  648 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~