답안 #1007046

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007046 2024-06-24T11:04:51 Z Haidara314 봉쇄 시간 (IOI23_closing) C++17
0 / 100
1000 ms 31928 KB
#include "closing.h"

#include <bits/stdc++.h>
#define S second
#define F first
#define ll long long
using namespace std;
vector<pair<int,ll>>adj[200005];
vector<int>v;
vector<ll>p;
void dfs(int u,int v1)
{
    v.push_back(u);
    for(auto x:adj[u])
    {
        if(x.F!=v1)
        {
            p.push_back(x.S);
            dfs(x.F,u);
        }
    }
}
int max_score(int N, int X, int Y, long long K,
              std::vector<int> U, std::vector<int> V, std::vector<int> W)
{
    p.clear();
    v.clear();
    for(int i=0;i<N;i++)
    {
        adj[i].clear();
    }
    for(int i=0;i<N-1;i++)
    {
        adj[U[i]].push_back({V[i],W[i]});
        adj[V[i]].push_back({U[i],W[i]});
        //cout<<U[i]<<" "<<V[i]<<endl;
    }
    ll ans=0;
    int x;
    for(int i=0;i<N;i++)
    {
        if(adj[i].size()==1){x=i;}
    }
    dfs(x,x);
    int s1;
    int s2;
    for(int i=0;i<N;i++)
    {
        if(v[i]==X)s1=i;
        if(v[i]==Y)s2=i;
    }
    ll o=0;
    vector<ll>ox;
    ox.push_back(0);
    for(int i=s1;i>0;i--)
    {
        o+=o+p[i-1];
        ox.push_back(o);
    }
    ox.pop_back();
    for(int i=0;i<=s1;i++)
    {
        //cout<<o<<endl;
        ll h=0;
        vector<ll>hx;
        hx.push_back(h);
        for(int i1=s2;i1>0;i1--)
        {
            h+=h+p[i1];
            hx.push_back(h);
        }
        hx.pop_back();
        for(int j=0;j<=s2;j++)
        {
            ll g=0;
            vector<ll>gx;
            gx.push_back(0);
            for(int i1=s1;i1<N-1;i1++){
                g+=g+p[i1];
                gx.push_back(g);
            }
            gx.pop_back();
            for(int k=N-1;k>=s1;k--)
            {
                //cout<<o<<" "<<h<<" "<<g<<endl;
                ll ans1=0;
                if(K>=g+h+o)
                {
                    ll k1=K-g-o-h;
                    ans1+=s1-i+1;
                    ans1+=s2-j+1;
                    ans1+=k-s1;
                    ll kk=0;
                    ans=max(ans,ans1);
                    for(int z=s2;z<N;z++)
                    {
                        if(kk<=k1)
                        {
                            ans=max(ans,ans1+z-s2);
                        }
                        kk+=kk+p[z];
                    }
                }
                g=gx[gx.size()-1];
                gx.pop_back();
            }
            h=hx[hx.size()-1];
            hx.pop_back();
        }
        o=ox[ox.size()-1];
        ox.pop_back();
    }
    return ans;
}
/*
1
7 0 2 10
 0 0 1 2 2 5
 1 3 2 4 5 6
 2 3 4 2 5 3
*/
/*
1
4 0 3 20
0 1 18
1 2 1
2 3 19
*/

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:44:8: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |     dfs(x,x);
      |     ~~~^~~~~
closing.cpp:46:9: warning: 's2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |     int s2;
      |         ^~
closing.cpp:45:9: warning: 's1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |     int s1;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4956 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1045 ms 31928 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '30', found: '18'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '30', found: '18'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Incorrect 2 ms 4956 KB 1st lines differ - on the 1st token, expected: '30', found: '18'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4956 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4956 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4956 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4956 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4956 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -