Submission #915384

# Submission time Handle Problem Language Result Execution time Memory
915384 2024-01-23T19:24:30 Z Ludissey Closing Time (IOI23_closing) C++17
0 / 100
1000 ms 28240 KB
#include <bits/stdc++.h>
#include "closing.h"

using namespace std;
#define int long long
#define sz(a){ return (int)a.size(); }

const int INF=1e9;
vector<vector<pair<int,int>>> edges;
vector<int> dstX;
vector<int> dstY;
vector<int> minXY;

signed max_score(signed N, signed rootX, signed rootY, long long K, std::vector<signed> U, std::vector<signed> V, std::vector<signed> W){
    edges.clear();
    dstX.clear();
    edges.resize(N);
    dstX.resize(N);
    dstY.resize(N);
    minXY.resize(N);

    for (int i = 0; i < N-1; i++)
    {
        edges[V[i]].push_back({U[i], W[i]});
        edges[U[i]].push_back({V[i], W[i]});
    }
    if(rootX>rootY) swap(rootX, rootY);
    vector<bool> visited(N);
    queue<pair<int,int>> queue;
    queue.push({rootX,0});
    while(!queue.empty()){
        int x=queue.front().first,w=queue.front().second; queue.pop();
        if(visited[x]) continue;
        visited[x]=true;
        dstX[x]=w;
        for (auto u: edges[x]) queue.push({u.first, u.second+w});
    }
    visited.clear();
    visited.resize(N);
    queue.push({rootY,0});
    while(!queue.empty()){
        int x=queue.front().first,w=queue.front().second; queue.pop();
        if(visited[x]) continue;
        visited[x]=true;   
        dstY[x]=w;
        for (auto u: edges[x]) queue.push({u.first, u.second+w});
    } 
    for (int i = 1; i < N; i++) minXY[i]=minXY[i-1]+min(dstX[i],dstY[i]);
    for (int i = rootX-1; i >= 0; i--) dstX[i]+=dstX[i+1];
    for (int i = rootX+1; i < N; i++) dstX[i]+=dstX[i-1];
    for (int i = rootY-1; i >= 0; i--) dstY[i]+=dstY[i+1];
    for (int i = rootY+1; i < N; i++) dstY[i]+=dstY[i-1];
    
    int mx=0;
    for (int l1 = rootX; l1 >= 0; l1--)
    {
        for (int r1 = rootX; r1 < N; r1++)
        {
            for (int l2 = rootY; l2 >= 0; l2--)
            {
                for (int r2 = rootY; r2 < N; r2++)
                {
                    int sum=0;
                    if((r1-l1)+(r2-l2)+2<mx) continue;
                    int _r1=r1, _l2=l2;
                    if(l2<r1) {
                        int mns=0;
                        if(l2>0) mns=minXY[l2-1];
                        sum+=minXY[r1]-mns;
                        swap(_r1,_l2);
                        _r1--;
                        _l2++;
                    }
                    sum+=dstX[l1];
                    if(r1>0) sum+=dstX[_r1];
                    if(_l2<N) sum+=dstY[_l2];
                    sum+=dstY[r2];
                    if(sum>K) continue;
                    mx=max((r1-l1)+(r2-l2)+2,mx);
                }
            }
        }
    }
    
    
    return (int)mx;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 28240 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 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 1 ms 344 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 1 ms 344 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 1 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '6', found: '4'
2 Halted 0 ms 0 KB -