Submission #1070764

# Submission time Handle Problem Language Result Execution time Memory
1070764 2024-08-22T18:06:50 Z HorizonWest Closing Time (IOI23_closing) C++17
0 / 100
1000 ms 42484 KB
//#include "closing.h"
#include <iostream>
#include <complex>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>
#include <bitset>
#include <queue>
#include <map>
#include <stack>
#include <cmath>
#include <cstdint>
#include <cassert>
using namespace std;
 
#define ll long long 
#define fs first 
#define sd second 
 
const ll Inf = 1e18 + 7;
 
vector <ll> bfs(int n, int x, vector <vector<pair<ll, ll >>> v)
{
    vector <ll> D(n + 1, Inf); queue <int> q; 
    D[x] = 0; q.push(x); 
 
    while (!q.empty())
    {
        int x = q.front(); q.pop();
 
        for(auto& u : v[x]) if(D[u.fs] == Inf)
        {   
            D[u.fs] = D[x] + u.sd; 
            q.push(u.fs);
        }
    }
    
    return D;
}


vector <int> line(int n, int x, int y, vector <vector<pair<ll, ll>>> v)
{
    vector <int> p(n, -1), s;  
    queue <int> q; q.push(x); p[x] = x;

    while (!q.empty())
    {
        int x = q.front(); q.pop();
 
        for(auto& u : v[x]) if(p[u.fs] == -1)
        {   
            p[u.fs] = x; 
            q.push(u.fs);
        }
    }

    while (true)
    {
        s.push_back(y);
        if(y == x) break;
        y = p[y];
    }

    reverse(s.begin(), s.end());
    
    return s;
}
 
int max_score(int n, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W)
{
    vector <vector<pair<ll, ll>>> v(n + 1,  vector <pair<ll, ll>> ());
 
    for(int i = 0; i < n - 1; i++)
    {
        v[U[i]].push_back({ V[i], W[i] });        
        v[V[i]].push_back({ U[i], W[i] });
    }
    
    vector <ll> d1 = bfs(n, X, v), d2 = bfs(n, Y, v);
    vector <int> s = line(n, X, Y, v); 
    int ans = 0, m = s.size() - 1; 


    for(int i = 0; i <= m; i++)
    { 
        for(int j = m; j >= 0; j--)
        {
            ll t = K; 

            priority_queue <pair<ll, pair<ll, ll>>> pq;
            vector <int> p(n);

            for(int k = j; k <= i; k++){
                t -= max(d1[s[k]], d2[s[k]]);
                pq.push({ 0, { s[k], 2 }});
            }

            for(int k = 0; k <= min(i, j-1); k++) if(p[s[k]] == 0){
                t -= d1[s[k]];
                pq.push({ 0, { s[k], 1 }});
            } else break;

            for(int k = m; k >= max(j, i+1); k--) if(p[s[k]] == 0){
                t -= d2[s[k]];
                pq.push({ 0, { s[k], 1 }});
            } else break;

            if(t < 0) continue;
            int tmp = 0;  
            //cerr << "NEW: " << endl;
            //cerr << i << " " << j << " " << t << endl;

            while (!pq.empty())
            {
                int x = pq.top().sd.fs, q = pq.top().sd.sd, w = -pq.top().fs; pq.pop();

                if(p[x]) continue;
                p[x] = 1; //cerr << x << " " << q << " " << w << endl;

                for(int k = 0; k < q; k++){
                    if(t - w >= 0){
                        t -= w;
                        tmp++;
                    }
                }

                for(auto& u : v[x]) if(!p[u.fs]){
                    pq.push({ -min(d1[u.fs], d2[u.fs]), { u.fs, q }});
                }        
            }

            ans = max(ans, tmp);
        }
    }
 

    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '7'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1055 ms 42484 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 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 0 ms 348 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 0 ms 348 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 348 KB 1st lines differ - on the 1st token, expected: '6', found: '7'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '7'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '7'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '7'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '6', found: '7'
2 Halted 0 ms 0 KB -