답안 #1007070

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007070 2024-06-24T11:24:07 Z Haidara314 봉쇄 시간 (IOI23_closing) C++17
0 / 100
1000 ms 27584 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);
    reverse(p.begin(),p.end());
    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;
    for(int i=s1;i>=0;i--)
    {
        ll h=0;
        for(int j=s2;j>=0;j--)
        {
            ll g=0;
            for(int k=s1;k<N;k++)
            {
                ll f=0;
                for(int z=s2;z<N;z++)
                {

                    if(K>=o+g+h+f){//cout<<i<<" "<<j<<" "<<k<<" "<<z<<" "<<s1-i+1+s2-j+1+k-s1+z-s2<<endl;
                    //cout<<o<<" "<<h<<" "<<g<<" "<<f<<endl;
                    ans=max(ans,(ll)(s1-i+1+s2-j+1+k-s1+z-s2));}
                    f+=f+p[z];
                }
                g+=g+p[k];
            }
            h+=h+p[j-1];
        }
        o+=o+p[i-1];
    }
    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: 's1' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |     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 1088 ms 27584 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Incorrect 1 ms 4956 KB 1st lines differ - on the 1st token, expected: '30', found: '21'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Incorrect 1 ms 4956 KB 1st lines differ - on the 1st token, expected: '30', found: '21'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Incorrect 1 ms 4956 KB 1st lines differ - on the 1st token, expected: '30', found: '21'
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 -