Submission #1064177

# Submission time Handle Problem Language Result Execution time Memory
1064177 2024-08-18T10:00:17 Z parsadox2 Closing Time (IOI23_closing) C++17
Compilation error
0 ms 0 KB
#include "closing.h"
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
const int N = 2e5 + 10;
int n , x , y;
long long dis[2][N] , k , psum[3][N];
vector <pair<int , int>> adj[N];

void Dfs(int v , int ty , int p = -1)
{
    for(auto u : adj[v])  if(u.F != p)
    {
        dis[ty][u.F] = dis[ty][v] + u.S;
        Dfs(u.F , ty , v);
    }
}

bool cmp(int aa , int bb)
{
    return min(dis[0][aa] , dis[1][aa]) < min(dis[0][bb] , dis[1][bb]);
}

long long Get(int l , int r , int ty)
{
    if(l > r)
        return 0;
    long long res = psum[ty][r];
    if(l > 0)
        res -= psum[ty][l - 1];
    return res;
}

int Solve(int l , int r)
{
    long long val = 0;
    int ans = 0;
    val = Get(l , r , 2);
    ans = 2 * (r - l + 1);
    val += Get(x , l , 0);
    ans += max(0LL , l - x);
    val += Get(r + 1 , y , 1);
    ans += max(0LL , y - r);
    if(val > k)
        return 0;
    int px = min(l , x) - 1 , py = max(r , y) + 1;
    while(px != -1 && py != n)
    {
        if(dis[0][px] <= dis[1][py])
        {
            if(val + dis[0][px] > k)
                break;
            ans++;
            val+= dis[0][px];
            px--;
            continue;
        }
        if(val + dis[1][py] > k)
            break;
        ans++;
        val += dis[1][py];
        py++;
    }
    while(py != n && val + dis[1][py] <= k)
    {
        val += dis[1][py];
        py++;
        ans++;
    }
    while(px != -1 && val + dis[0][px] <= k)
    {
        val += dis[0][px];
        px--;
        ans++;
    }
    return ans;
}

int max_score(int nn, int X, int Y, long long K,
              vector<int> U, vector<int> V, vector<int> W)
{
    n = nn;
    x = X;
    y = Y;
    k = K;
    if(x > y)
        swap(x , y);
    for(int i = 0 ; i < n ; i++)
        adj[i].clear();
    for(int i = 0 ; i < n - 1 ; i++)
    {
        adj[U[i]].push_back(make_pair(V[i] , W[i]));
        adj[V[i]].push_back(make_pair(U[i] , W[i]));
    }
    //cout << x << " " << y << endl;
    dis[0][x] = 0;
    Dfs(x , 0);
    dis[1][y] = 0;
    Dfs(y , 1);
    psum[0][0] = dis[0][0];
    psum[1][0] = dis[1][0];
    psum[2][0] = max(dis[0][0] , dis[1][0]);
    for(int i = 1 ; i < n ; i++)
    {
        psum[0][i] = dis[0][i] + psum[0][i - 1];
        psum[1][i] = dis[1][i] + psum[1][i - 1];
        psum[2][i] = max(dis[0][i] , dis[1][i]) + psum[2][i - 1];
    }
    int ans = 0;
    for(int l = 0 ; l < n ; l++)  for(int r = l ; r < n ; r++)
    {
        ans = max(ans , Solve(l , r));
    }
    vector <long long> all;
    for(int i = 0 ; i < n ; i++)
    {
        //cout << i << " : " << dis[0][i] << " " << dis[1][i] << endl;
        all.push_back(min(dis[0][i] , dis[1][i]));
    }
    sort(all.rbegin() , all.rend());
    int ans2 = 0;
    while(!all.empty() && k >= all.back())
    {
        k -= all.back();
        all.pop_back();
        ans2++;
    }
    return max(ans , ans2);
}

Compilation message

closing.cpp: In function 'int Solve(int, int)':
closing.cpp:42:27: error: no matching function for call to 'max(long long int, int)'
   42 |     ans += max(0LL , l - x);
      |                           ^
In file included from /usr/include/c++/10/vector:60,
                 from closing.h:1,
                 from closing.cpp:1:
/usr/include/c++/10/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++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
closing.cpp:42:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   42 |     ans += max(0LL , l - x);
      |                           ^
In file included from /usr/include/c++/10/vector:60,
                 from closing.h:1,
                 from closing.cpp:1:
/usr/include/c++/10/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++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
closing.cpp:42:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   42 |     ans += max(0LL , l - x);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from closing.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
closing.cpp:42:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   42 |     ans += max(0LL , l - x);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from closing.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
closing.cpp:42:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   42 |     ans += max(0LL , l - x);
      |                           ^
closing.cpp:44:27: error: no matching function for call to 'max(long long int, int)'
   44 |     ans += max(0LL , y - r);
      |                           ^
In file included from /usr/include/c++/10/vector:60,
                 from closing.h:1,
                 from closing.cpp:1:
/usr/include/c++/10/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++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
closing.cpp:44:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   44 |     ans += max(0LL , y - r);
      |                           ^
In file included from /usr/include/c++/10/vector:60,
                 from closing.h:1,
                 from closing.cpp:1:
/usr/include/c++/10/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++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
closing.cpp:44:27: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   44 |     ans += max(0LL , y - r);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from closing.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
closing.cpp:44:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   44 |     ans += max(0LL , y - r);
      |                           ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from closing.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
closing.cpp:44:27: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   44 |     ans += max(0LL , y - r);
      |                           ^