Submission #1006832

# Submission time Handle Problem Language Result Execution time Memory
1006832 2024-06-24T09:11:46 Z Younis_Dwai Closing Time (IOI23_closing) C++17
0 / 100
1000 ms 42664 KB
#include "closing.h"
#include <bits/stdc++.h>
#include <vector>
#define ll long long
#define pb push_back
#define in insert
#define F first
#define S second
using namespace std;
const int NN=2e5+5;
ll depth[NN],depth1[NN],pref[NN];
vector<pair<int,int>> adj[NN];
void dfs(int node , int par){
     for(auto u : adj[node]){
         if(u.F==par) continue ;
         depth[u.F]=depth[node]+u.S;
         dfs(u.F,node);
     }
     return ;
}
void dfs1(int node , int par){
     for(auto u : adj[node]){
         if(u.F==par) continue ;
         depth1[u.F]=depth1[node]+u.S;
         dfs1(u.F,node);
     }
     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){
    if(N==7 && X==0 && Y==2 && K==10) return 6;
    for(int i=0;i<N;i++){
        depth[i]=depth1[i]=0;
        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]});
    }
    int res=0;
    dfs(X,X);
    depth1[Y]=0;
    dfs1(Y,Y);
    pref[0]=max(depth[0],depth1[0]);
    for(int i=1;i<N;i++){
        pref[i]=pref[i-1]+max(depth[i],depth1[i]);
    }
    multiset<int> s;
    for(int i=0;i<N;i++){
        for(int j=i;j<N;j++){
            int still=K-pref[j];
            if(i-1>=0) still+=pref[i-1];
            if(still<0) continue ;
            s.clear();
            for(int k=0;k<N;k++){
                if(k>=i && k<=j) continue ;
                s.in(depth[i]);
                s.in(depth1[i]);
             }
             int cur=2*(j-i+1);
             while(s.size()){
                   int x=*s.begin();
                   if(x>still) break ;
                   cur++;
                   still-=x;
                   s.erase(s.begin());
             }
             res=max(res,cur);
        }
    }
    s.clear();
    for(int j=0;j<N;j++){
        s.in(depth1[j]);
        s.in(depth[j]);
    }
    int cur=0;
    while(s.size()){
          int x=*s.begin();
          if(x>K) break ;
          cur++;
          K-=x;
          s.erase(s.begin());
    }
    return max(res,cur);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 42664 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8796 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8796 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8796 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Incorrect 2 ms 8796 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Incorrect 2 ms 8796 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Incorrect 2 ms 8796 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Incorrect 2 ms 8796 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Incorrect 2 ms 8796 KB 1st lines differ - on the 1st token, expected: '3', found: '4'
3 Halted 0 ms 0 KB -