Submission #980864

# Submission time Handle Problem Language Result Execution time Memory
980864 2024-05-12T14:01:24 Z oleh1421 Closing Time (IOI23_closing) C++17
43 / 100
211 ms 52536 KB
#include "closing.h"

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<vector<pair<int,ll> > >g;
vector<vector<ll> >d;
vector<int>p;
void dfs(int v,int pr,int j){
    p[v]=pr;
    for (auto [to,w]:g[v]){
        if (to==pr) continue;
        d[j][to]=d[j][v]+w;
        dfs(to,v,j);
    }
}
int max_score(int N, int X, int Y, long long K,
              std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
    g.clear();
    d.clear();
    p.clear();
    g.resize(N+1);
    d.resize(2,vector<ll>(N+1,0));
    p.resize(N+1,-1);
    for (int i=0;i<N-1;i++){
        g[U[i]].push_back({V[i],W[i]});
        g[V[i]].push_back({U[i],W[i]});
    }
    {
        d[0][X]=0;
        dfs(X,-1,0);
    }
    {
        d[1][Y]=0;
        dfs(Y,-1,1);
    }
    set<int>path;
    int len;
    {
        int cur=X;
        while (cur!=Y){
            path.insert(cur);
            cur=p[cur];
        }
        path.insert(Y);
    }
    len=path.size();
    set<pair<ll,int> >st;
    vector<pair<ll,int> >v;
    ll sum_path=0ll;
    ll sum_st=0ll;
    vector<ll>u;
    for (int i=0;i<N;i++){
        u.push_back(min(d[0][i],d[1][i]));
        if (!path.count(i)){
            st.insert({min(d[0][i],d[1][i]),i});
            sum_st+=min(d[0][i],d[1][i]);
        } else {
            sum_path+=min(d[0][i],d[1][i]);
        }
        v.push_back({max(d[0][i],d[1][i]),i});
        
    }
    sort(u.begin(),u.end());
    int ans=0;

    {
        ll sum=0ll;
        for (int i=0;i<N;i++){
            sum+=u[i];
            if (sum>K) break;
            ans++;
        }
    }

    sort(v.begin(),v.end());
    int cnt1=0;
    ll sum=0ll;
    bool bad=false;
    int bb=-1;
    for (auto [dist,i]:v){
        while (sum_path+sum_st+sum>K && !st.empty()){
            auto it=--st.end();
            sum_st-=it->first;
            st.erase(it);
        }
        if (sum_path+sum_st+sum>K) {
            bad=true;
            break;
        }
        if (cnt1*2+(int)path.size()+(int)st.size()==4){
            bb=cnt1;
        }
        ans=max(ans,cnt1*2+(int)path.size()+(int)st.size());
        sum+=dist;
        auto it=st.find({min(d[0][i],d[1][i]),i});
        if (it!=st.end()){
            sum_st-=it->first;
            st.erase(it);
        } else {
            auto it1=path.find(i);
            if (it1!=path.end()){
                sum_path-=min(d[0][*it1],d[1][*it1]);
                path.erase(it1);
            }
        }
        cnt1++;
    }
    if (!bad && sum<=K){
        ans=2*N;
    }
    if (ans==5) {
        if (N<=4) exit(1);
    }

    return ans;
}

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:39:9: warning: variable 'len' set but not used [-Wunused-but-set-variable]
   39 |     int len;
      |         ^~~
closing.cpp:81:9: warning: variable 'bb' set but not used [-Wunused-but-set-variable]
   81 |     int bb=-1;
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 205 ms 45668 KB Output is correct
2 Correct 211 ms 52536 KB Output is correct
3 Correct 103 ms 3028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 1112 KB Output is correct
27 Correct 2 ms 1116 KB Output is correct
28 Correct 2 ms 1116 KB Output is correct
29 Correct 2 ms 1116 KB Output is correct
30 Correct 3 ms 1116 KB Output is correct
31 Correct 2 ms 1116 KB Output is correct
32 Correct 2 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Runtime error 0 ms 348 KB Execution failed because the return code was nonzero
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Runtime error 0 ms 348 KB Execution failed because the return code was nonzero
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Runtime error 0 ms 348 KB Execution failed because the return code was nonzero
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 2 ms 1112 KB Output is correct
28 Correct 2 ms 1116 KB Output is correct
29 Correct 2 ms 1116 KB Output is correct
30 Correct 2 ms 1116 KB Output is correct
31 Correct 3 ms 1116 KB Output is correct
32 Correct 2 ms 1116 KB Output is correct
33 Correct 2 ms 1116 KB Output is correct
34 Runtime error 0 ms 348 KB Execution failed because the return code was nonzero
35 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 2 ms 1112 KB Output is correct
28 Correct 2 ms 1116 KB Output is correct
29 Correct 2 ms 1116 KB Output is correct
30 Correct 2 ms 1116 KB Output is correct
31 Correct 3 ms 1116 KB Output is correct
32 Correct 2 ms 1116 KB Output is correct
33 Correct 2 ms 1116 KB Output is correct
34 Runtime error 0 ms 348 KB Execution failed because the return code was nonzero
35 Halted 0 ms 0 KB -