QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#153870#7118. Closing TimeLynkcat#0 127ms51456kbC++203.1kb2023-08-31 09:43:142023-08-31 09:43:15

Judging History

你现在查看的是测评时间为 2023-08-31 09:43:15 的历史记录

  • [2024-04-28 06:29:43]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:140ms
  • 内存:51356kb
  • [2023-08-31 09:43:15]
  • 评测
  • 测评结果:0
  • 用时:127ms
  • 内存:51456kb
  • [2023-08-31 09:43:14]
  • 提交

answer

#include "closing.h"
#include<bits/stdc++.h>
#define poly vector<ll>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < ll,ll >
#define fi first
#define se second
#define inf 1e18
#define mod 998244353
// #define int ll
// #define N 
using namespace std;
void dfs(int k,int fa,poly &dis,vector<vector<pa>> &G)
{
    for (auto [u,w]:G[k])
    {
        if (u==fa) continue;
        dis[u]=dis[k]+w;
        dfs(u,k,dis,G);
    }
}
int max_score(int n, int X, int Y, long long K,
              std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
    poly dx(n,0),dy(n,0);
    vector<vector<pa>>G(n,vector<pa>());
    for (int i=0;i+1<n;i++)
        G[U[i]].push_back(mp(V[i],W[i])),
        G[V[i]].push_back(mp(U[i],W[i]));
    dfs(X,X,dx,G);
    dfs(Y,Y,dy,G);
    // cerr<<"!!!!!!"<<endl;
    int ans=0;
    {
        priority_queue<pa>q;
        vector<bool>vis(n,0);
        for (int i=0;i<n;i++)
            q.push(mp(-dx[i],i)),q.push(mp(-dy[i],i));
        int sm=0;
        int now=0;
        while (!q.empty())
        {
            int u=q.top().se;
            int w=-q.top().fi;
            q.pop();
            if (vis[u]) continue;
            vis[u]=1;
            sm+=w;
            if (sm>K) break;
            now++;
        }
        ans=max(ans,now);
        // cerr<<"??"<<now<<endl;
    }
    {
        priority_queue<pa,vector<pa>,greater<pa>>q;
        priority_queue<pa>qs;
        vector<int>vis(n,0);
        vector<poly>val(n,poly(2,0));
        ll mn=dx[0]+dy[0];
        for (int i=0;i<n;i++)
        {
            if (dx[i]+dy[i]<mn) mn=min(mn,dx[i]+dy[i]);
        }
        int now=0;
        for (int i=0;i<n;i++)
            if (dx[i]+dy[i]==mn) K-=min(dx[i],dy[i]),vis[i]=1,q.push(mp(abs(dx[i]-dy[i]),i)),now++;
            else
            {
                // cout<<"!!!"<<i<<endl;
                vis[i]=0;
                q.push(mp(min(dx[i],dy[i]),i));
                val[i][0]=min(dx[i],dy[i]);
                val[i][1]=abs(dx[i]-dy[i]);
            }
        if (K>=0)
        {
            while (!q.empty())
            {
                int u=q.top().se;
                int w=q.top().fi;
                q.pop();
                if (K<w)
                {
                    if (qs.size()&&K+qs.top().fi-w>=0)
                    {
                        // cerr<<"th "<<u<<" "<<w<<endl;
                        int v=qs.top().se;
                        K+=qs.top().fi-w;
                        vis[v]--;
                        qs.pop();
                        qs.push(mp(val[u][vis[u]],u));
                        vis[u]++;
                        q.push(mp(val[v][vis[v]],v));
                    }
                } else
                {
                    // cerr<<"ins "<<u<<" "<<w<<endl;
                    K-=w;
                    qs.push(mp(val[u][vis[u]],u));
                    vis[u]++;
                    now++;
                }
            }
            ans=max(ans,now);
        }
    }
    return ans;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 127ms
memory: 51456kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
200000 31011 61157 8517583098
31011 129396 964383
1655 129396 331139
1655 191487 566483
110385 191487 865248
43212 110385 542661
43212 81682 13766
81682 91774 546589
91774 124706 780638
124706 175650 118706
10421 175650 615314
10421 151953 436270
140430 151...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
200000

result:

wrong answer 1st lines differ - on the 1st token, expected: '451', found: '200000'

Subtask #2:

score: 0
Wrong Answer

Test #4:

score: 0
Wrong Answer
time: 1ms
memory: 3648kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
50 23 25 382806473
0 1 375710
1 2 898637
2 3 10402
3 4 536577
4 5 385023
5 6 71075
6 7 543368
7 8 301497
8 9 174394
9 10 711312
10 11 923006
11 12 675532
12 13 838667
13 14 565729
14 15 979816
15 16 862618
16 17 576015
17 18 177751
18 19 306989
19 20 881492...

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
53

result:

wrong answer 1st lines differ - on the 1st token, expected: '96', found: '53'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Wrong Answer

Test #36:

score: 0
Wrong Answer
time: 1ms
memory: 3668kb

input:

cc61ad56a4797fb3f5c9529f73ce6fcedd85669b
1
4 0 1 9
0 2 2
1 2 3
2 3 3

output:

081ce3c351cbf526b37954b9ad30f2b531a7585c
OK
5

result:

wrong answer 1st lines differ - on the 1st token, expected: '6', found: '5'

Subtask #6:

score: 0
Skipped

Dependency #2:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #4:

0%

Subtask #9:

score: 0
Skipped

Dependency #1:

0%