Submission #1078809

# Submission time Handle Problem Language Result Execution time Memory
1078809 2024-08-28T06:25:42 Z PoPularPlusPlus Closing Time (IOI23_closing) C++17
9 / 100
111 ms 25424 KB
#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define vf first
#define vs second

int max_score(int n, int x, int y, ll k,vector<int> u, vector<int> v, vector<int> w){
    int ans = 2;
    vector<pair<int,ll>> adj[n];
    for(int i = 0; i < n-1; i++){
        adj[u[i]].pb(mp(v[i] , w[i]));
        adj[v[i]].pb(mp(u[i] , w[i]));
    }

    int dis1[n] , dis2[n];
    memset(dis1,-1,sizeof dis1);
    memset(dis2,-1,sizeof dis2);

    queue<int> q;
    q.push(x);
    dis1[x] = 0;
    while(q.size()){
        int node = q.front();
        q.pop();
        for(auto it : adj[node]){
            if(dis1[it.vf] == -1){
                dis1[it.vf] = dis1[node] + it.vs;
                q.push(it.vf);
            }
        }
    }


    dis2[y] = 0;
    q.push(y);

    while(q.size()){
        int node = q.front();
        q.pop();
        for(auto it : adj[node]){
            if(dis2[it.vf] == -1){
                dis2[it.vf] = dis2[node] + it.vs;
                q.push(it.vf);
            }
        }
    }

    bool visx[n] , visy[n];

    for(int i = 0; i < (1 << n); i++){
        int res = 0;
        ll rem = k;
        memset(visx,0,sizeof visx);
        memset(visy,0,sizeof visy);

        if(((1 << x) & i)){
            visx[x] = 0;
            q.push(x);
            while(q.size()){
                int node = q.front();
                q.pop();
                for(auto it : adj[node]){
                    if(!visx[it.vf]){
                        if((i & (1 << it.vf))){
                            visx[it.vf] = 1;
                            q.push(it.vf);
                        }
                    }
                }
            }
        }

        if(((1 << y) & i)){
            visy[x] = 0;
            q.push(x);
            while(q.size()){
                int node = q.front();
                q.pop();
                for(auto it : adj[node]){
                    if(!visy[it.vf]){
                        if((i & (1 << it.vf))){
                            visy[it.vf] = 1;
                            q.push(it.vf);
                        }
                    }
                }
            }
        }

        vector<int> v;
        for(int j = 0; j < n; j++){
            if((i & (1 << j))){
                if(visx[j] && visy[j]){
                    res++;
                    rem -= min(dis1[j] , dis2[j]);
                    v.pb(max(dis1[j] , dis2[j]) - min(dis2[j] , dis1[j]));
                }
                else if(visx[j]){
                    rem -= dis1[j];
                    res++;
                }
                else if(visy[j]){
                    rem -= dis2[j];
                    res++;
                }
            }
        }

        if(rem >= 0){
            sort(all(v));
            for(int i : v){
                if(rem - i >= 0){
                    res++;
                    rem -= i;
                }
            }

            ans = max(ans , res);
        }
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 25424 KB 1st lines differ - on the 1st token, expected: '451', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 105 ms 348 KB Output is correct
3 Correct 110 ms 344 KB Output is correct
4 Correct 96 ms 348 KB Output is correct
5 Correct 53 ms 344 KB Output is correct
6 Incorrect 36 ms 592 KB 1st lines differ - on the 1st token, expected: '96', found: '2'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 105 ms 348 KB Output is correct
3 Correct 110 ms 344 KB Output is correct
4 Correct 96 ms 348 KB Output is correct
5 Correct 53 ms 344 KB Output is correct
6 Incorrect 36 ms 592 KB 1st lines differ - on the 1st token, expected: '96', found: '2'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 105 ms 348 KB Output is correct
3 Correct 110 ms 344 KB Output is correct
4 Correct 96 ms 348 KB Output is correct
5 Correct 53 ms 344 KB Output is correct
6 Incorrect 36 ms 592 KB 1st lines differ - on the 1st token, expected: '96', found: '2'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 105 ms 348 KB Output is correct
4 Correct 110 ms 344 KB Output is correct
5 Correct 96 ms 348 KB Output is correct
6 Correct 53 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 24 ms 348 KB Output is correct
11 Correct 57 ms 348 KB Output is correct
12 Correct 4 ms 348 KB Output is correct
13 Correct 99 ms 348 KB Output is correct
14 Correct 57 ms 344 KB Output is correct
15 Correct 25 ms 348 KB Output is correct
16 Correct 28 ms 436 KB Output is correct
17 Correct 23 ms 348 KB Output is correct
18 Correct 46 ms 348 KB Output is correct
19 Correct 111 ms 344 KB Output is correct
20 Correct 22 ms 344 KB Output is correct
21 Correct 22 ms 344 KB Output is correct
22 Correct 105 ms 344 KB Output is correct
23 Correct 89 ms 348 KB Output is correct
24 Correct 25 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 105 ms 348 KB Output is correct
4 Correct 110 ms 344 KB Output is correct
5 Correct 96 ms 348 KB Output is correct
6 Correct 53 ms 344 KB Output is correct
7 Incorrect 36 ms 592 KB 1st lines differ - on the 1st token, expected: '96', found: '2'
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 105 ms 348 KB Output is correct
4 Correct 110 ms 344 KB Output is correct
5 Correct 96 ms 348 KB Output is correct
6 Correct 53 ms 344 KB Output is correct
7 Incorrect 36 ms 592 KB 1st lines differ - on the 1st token, expected: '96', found: '2'
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 105 ms 348 KB Output is correct
4 Correct 110 ms 344 KB Output is correct
5 Correct 96 ms 348 KB Output is correct
6 Correct 53 ms 344 KB Output is correct
7 Incorrect 36 ms 592 KB 1st lines differ - on the 1st token, expected: '96', found: '2'
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 105 ms 348 KB Output is correct
4 Correct 110 ms 344 KB Output is correct
5 Correct 96 ms 348 KB Output is correct
6 Correct 53 ms 344 KB Output is correct
7 Incorrect 36 ms 592 KB 1st lines differ - on the 1st token, expected: '96', found: '2'
8 Halted 0 ms 0 KB -