Submission #1076361

# Submission time Handle Problem Language Result Execution time Memory
1076361 2024-08-26T13:17:47 Z MarwenElarbi Closing Time (IOI23_closing) C++17
0 / 100
110 ms 27088 KB
#include <bits/stdc++.h>
#include "closing.h"
using namespace std;
#define pb push_back
#define fi first
#define se second
const int nax = 2e5+5;
const int MOD = 1e9+7;
vector<pair<int,int>> adj[nax];
vector<long long> a,b;
void dfs(int x,int p,int cur,int type){
    (type ? a : b).pb(cur);
    for(auto u:adj[x]){
        if(u.fi==p) continue;
        dfs(u.fi,x,cur+u.se,type);
    }
    return;
}
int max_score(int N, int X, int Y, long long K,
              std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
    a.clear();
    b.clear();
    for(int i=0 ; i < N ;i++) adj[i].clear();
    for (int i = 0; i < N-1; ++i)
    {
        adj[U[i]].pb({V[i],W[i]});
        adj[V[i]].pb({U[i],W[i]});
    }
    dfs(X,-1,0,0);
    dfs(Y,-1,0,1);
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    long long pre[N];
    memset(pre,0,sizeof pre);
    for (int i = 1; i < N; ++i) pre[i]=b[i]+pre[i-1];
    int ans=0;
    for (int i = 0; i < N; ++i)
    {
        int l=0;
        int r=N;
        K-=a[i];
        if(K<0) break;
        while(r-l>1){
            int mid=(r+l)/2;
            if(pre[mid]>K) r=mid;
            else l=mid;
        }
        ans=max(ans,l+i+2);
    } 
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4952 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 110 ms 27088 KB 1st lines differ - on the 1st token, expected: '451', found: '400000'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '30', found: '24'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4952 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4952 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4952 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4952 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4952 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -